Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗺 Add ESM template #5452

Closed
mcansh opened this issue Feb 14, 2023 · 17 comments
Closed

🗺 Add ESM template #5452

mcansh opened this issue Feb 14, 2023 · 17 comments
Assignees
Labels
feat:dx Issues related to the developer experience

Comments

@mcansh
Copy link
Collaborator

mcansh commented Feb 14, 2023

No description provided.

@mcansh mcansh converted this from a draft issue Feb 14, 2023
@mcansh mcansh self-assigned this Feb 14, 2023
@mcansh
Copy link
Collaborator Author

mcansh commented Feb 14, 2023

@mcansh mcansh moved this from Planned to In Progress in Roadmap Feb 14, 2023
@mcansh mcansh linked a pull request Feb 15, 2023 that will close this issue
2 tasks
@mcansh
Copy link
Collaborator Author

mcansh commented Feb 15, 2023

PR for express and netlify #5454

Fly, Remix, and Vercel templates all use remix-serve and remix dev which doesn't currently support importing ESM files - i'll adjust remix-serve and then add those if desired

@mcansh mcansh moved this from In Progress to Planned in Roadmap Feb 21, 2023
@jacob-ebey
Copy link
Member

For the new node-esm template, can we require node 18 and use the built in --watch flag to remove a dependency on nodemon?

@mcansh
Copy link
Collaborator Author

mcansh commented Feb 22, 2023

For the new node-esm template, can we require node 18 and use the built in --watch flag to remove a dependency on nodemon?

most definitely

@MichaelDeBoey
Copy link
Member

@jacob-ebey @mcansh What about updating all templates to require Node 18 to make it consistent?

I would even suggest to make all remix packages to require Node 18 as well as 14 & 16 are EOL for some time now 🤔

@ctrlplusb
Copy link

So keen to see a remix project using "type": "module" in the package.json and with TypeScript configured to resolve and output ESM. I tried, but couldn't get it working.

@mcansh
Copy link
Collaborator Author

mcansh commented Mar 17, 2023

So keen to see a remix project using "type": "module" in the package.json and with TypeScript configured to resolve and output ESM. I tried, but couldn't get it working.

the "express-esm" template in the linked PR works great for me on macOS, i'll double check windows. I'd love to get that merged if we can fix your issues :)

@ctrlplusb
Copy link

ctrlplusb commented Mar 20, 2023

@mcansh I'll try again. When I tried running "type": "module", I also set my TypeScript config to be NodeNext etc. I then tried running the project via remix dev (Remix App Server) and it complained that the remix-serve / remix-express packages have CJS require statements, which aren't supported by ESM.

I looked at the dist for those packages and they do indeed only have CJS outs, no ESM options.

@mcansh
Copy link
Collaborator Author

mcansh commented Mar 21, 2023

I'll try again. When I tried running "type": "module", I also set my TypeScript config to be NodeNext etc. I then tried running the project via remix dev (Remix App Server) and it complained that the remix-serve / remix-express packages have CJS require statements, which aren't supported by ESM.

I looked at the dist for those packages and they do indeed only have CJS outs, no ESM options.

ah yea, you'll need to use a dedicated server for now https://github.com/mcansh/express-esm

@lensbart
Copy link
Contributor

ah yea, you'll need to use a dedicated server for now https://github.com/mcansh/express-esm

Thanks for this suggestion!

Even with that approach, I get the same error as mentioned above for the yarn dev:remix command. The yarn start script however does work as expected.

Error: require() of ES Module packages/app/build/index.js from node_modules/@remix-run/serve/dist/index.js not supported.
Instead change the require of packages/app/build/index.js in node_modules/@remix-run/serve/dist/index.js to a dynamic import() which is available in all CommonJS modules.

@mcansh
Copy link
Collaborator Author

mcansh commented Apr 19, 2023

ah yea, you'll need to use a dedicated server for now https://github.com/mcansh/express-esm

Thanks for this suggestion!

Even with that approach, I get the same error as mentioned above for the yarn dev:remix command. The yarn start script however does work as expected.

Error: require() of ES Module packages/app/build/index.js from node_modules/@remix-run/serve/dist/index.js not supported.

Instead change the require of packages/app/build/index.js in node_modules/@remix-run/serve/dist/index.js to a dynamic import() which is available in all CommonJS modules.

sounds like you're missing "type": "module" in package.json

@lensbart
Copy link
Contributor

Thanks for the quick reply! I do have "type": "module" in the package.json of my Remix app. I think this require() is the culprit, and (if my understanding is correct) @remix-run/serve still gets used by the dev:remix script in https://github.com/mcansh/express-esm — it’s just the start script that uses the ESM-compatible server.js file.

@lensbart
Copy link
Contributor

lensbart commented Apr 19, 2023

Another issue seems to be that { assert: { type: 'json' } } as a second argument to dynamic import() seems to get stripped in build/index.js, even when serverModuleFormat: 'esm' is specified in remix.config.js.

This creates an error when running the app as ESM:

TypeError: [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "packages/app/public/lang/en.json" needs an import assertion of type "json"

@mcansh
Copy link
Collaborator Author

mcansh commented Apr 20, 2023

Thanks for the quick reply! I do have "type": "module" in the package.json of my Remix app. I think this require() is the culprit, and (if my understanding is correct) @remix-run/serve still gets used by the dev:remix script in https://github.com/mcansh/express-esm — it’s just the start script that uses the ESM-compatible server.js file.

ah, are you using unstable_dev? the repo works for me using it as remix dev using the new dev server does not also serve the app.

@mcansh
Copy link
Collaborator Author

mcansh commented Apr 20, 2023

Another issue seems to be that { assert: { type: 'json' } } as a second argument to dynamic import() seems to get stripped in build/index.js, even when serverModuleFormat: 'esm' is specified in remix.config.js.

This creates an error when running the app as ESM:

TypeError: [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "packages/app/public/lang/en.json" needs an import assertion of type "json"

this part is due to our compiler not supporting import assertions yet, i'll talk with @pcattori if we should add @babel/plugin-syntax-import-assertions - tried it locally and it's working ay-okay for dev, but busted for builds

@jacob-ebey
Copy link
Member

I've updated the express template to ESM as part #6229

@brophdawg11 brophdawg11 added the feat:dx Issues related to the developer experience label May 4, 2023
@ryanflorence
Copy link
Member

@jacob-ebey correct me if I'm wrong, but everything is ESM in v2 so we can close thise.

@github-project-automation github-project-automation bot moved this from Planned to Merged in Roadmap Aug 23, 2023
@MichaelDeBoey MichaelDeBoey changed the title Add ESM template 🗺 Add ESM template Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat:dx Issues related to the developer experience
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants