fedeya / remix-sitemap

Sitemap generator for Remix applications
https://npmjs.com/remix-sitemap
MIT License
95 stars 5 forks source link

Build time generation does not work with esm/typescript #67

Closed danthegoodman1 closed 3 weeks ago

danthegoodman1 commented 8 months ago
file:///Users/dangoodman/code/sellmyai/remix-sitemap.config.js:2
module.exports = {
^

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/dangoodman/code/sellmyai/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/dangoodman/code/sellmyai/remix-sitemap.config.js:2:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
    at async main (/Users/dangoodman/code/sellmyai/node_modules/remix-sitemap/dist/cli.js:539:35)

Node.js v20.10.0
danthegoodman1 commented 8 months ago

Obviously if you rename it to .cjs it cannot find the file since it looks for that exact file path.

fedeya commented 8 months ago

Hi @danthegoodman1 with type: module you can use export default instead of module.exports

danthegoodman1 commented 8 months ago

gotcha, will try that when I revisit sitemapping as I just made my own quickly. Would be great to mention in the docs!

danthegoodman1 commented 8 months ago

esp since remix templates are all esm by default now

jam-fran commented 8 months ago

@fedeya My remix app is in a monorepo, and I'm bundling some internal packages when I build the app. When I use export default in my remix-sitemap.config.js I get an ESM error:

🔍 Found config file: file:///Users/jamfran/Documents/Projects/myproject/apps/marketing-site/remix-sitemap.config.js
🔍 Generating sitemap...
🔍 Found routes: root, routes/_layout._legal.privacy, routes/_layout._legal.terms, routes/_layout.blog_.$slug, routes/_layout.pricing, routes/_layout._index, routes/_layout._legal, routes/_layout.blog, routes/_layout
/Users/jamfran/Documents/Projects/myproject/packages/ui/src/index.tsx:1
export * from './Accordion'
^^^^^^

SyntaxError: Unexpected token 'export'

Let me know if you have any troubleshooting tips. Thank you!

AdiRishi commented 5 months ago

@fedeya My remix app is in a monorepo, and I'm bundling some internal packages when I build the app. When I use export default in my remix-sitemap.config.js I get an ESM error:

🔍 Found config file: file:///Users/jamfran/Documents/Projects/myproject/apps/marketing-site/remix-sitemap.config.js
🔍 Generating sitemap...
🔍 Found routes: root, routes/_layout._legal.privacy, routes/_layout._legal.terms, routes/_layout.blog_.$slug, routes/_layout.pricing, routes/_layout._index, routes/_layout._legal, routes/_layout.blog, routes/_layout
/Users/jamfran/Documents/Projects/myproject/packages/ui/src/index.tsx:1
export * from './Accordion'
^^^^^^

SyntaxError: Unexpected token 'export'

Let me know if you have any troubleshooting tips. Thank you!

Just ran into this with turborepo myself. Did you find a solution?

robertwach commented 3 months ago

Using export default fixes the issue