Allow es modules to be imported in `next-sitemap.js`.
See original GitHub issueIs your feature request related to a problem? Please describe.
Right now it is not possible to import es modules in next-sitemap.js
.
For example: paths.js
export const somePath = 'some/path'
next-sitemap.js
import { somePath } from './paths'
or
const { somePath } = require('./paths')
Both of these won’t work. In other words, it is in no way possible to import an es module into next-sitemap.js
.
I could imagine that many next.js users have a paths.js file containing all of their app’s paths. E.g. one would import these into next-sitemap.js
to exclude a path.
Describe the solution you’d like There are multiple solutions:
- import
next-sitemap.js
(inside next-sitemap src code) using theimport
statement as opposed to using the require statement. This would effectively makenext-sitemap.js
an es module being able to import other es modules. Without using Babel it is necessary though to renamenext-sitemap.js
tonext-sitemap.mjs
to use theimport
syntax. Or adding{ type: 'module' }
topackage.json
. - let Babel process
next-sitemap.js
before executing it using the@babel-node
package for example.
Describe alternatives you’ve considered
The only alternative I see right now is to hardcode any values you’d like to import and thereby duplicating them. But if the values change and one forgets to update the hardcoded values in next-sitemap.js
, things will obviously break…
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:12
Top GitHub Comments
Hi all! unfortunatly the issue still exists.
I’m getting this error message:
yep this is how I solved this too ^. More info - https://www.kishokanth.com/blog/how-to-fix-postbuild-error-when-using-next-sitemap