Open robertIsaac opened 1 year ago
ah bloody hell, I've just hit this :( Is there a workaround ?
ah bloody hell, I've just hit this :( Is there a workaround ?
if you don't use plugins, npx tsc --project .\apps\nx-nest-esm\tsconfig.app.json
then node .\dist\out-tsc\apps\nx-nest-esm\src\main.js
:)
@AgentEnder any updates?
We'll need to patch @nx/webpack
to adapt webpack.config.js
files that use ESM. The only workaround in the meantime ifs to rename the file to webpack.config.ts
, which Nx will transpile to CommonJS, or don't use ESM in the .js
config file.
We can land the fix maybe in a few weeks unless people are completely blocked even with the above workarounds.
@jaysoo I don't get what webpack.config.js
I need to rename to webpack.config.ts
I don't have any webpack.config.js
in my project
oh in the reprod repo there is a webpack file
it didn't work, added you to the repo, feel free to add a commit to fix it
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐
I need to write a comment to stop the bot from closing the issue
Is there any workaround or working solution to that issue? I'm encountering more and more packages that are ESM only
Pinging this thread in case anyone has managed to figure out a fix. Node v22 added in the experimental flag to automatically patch in support for require()
calls in ESM graphs. This flag is --experimental-require-module
.
Does anyone know how to incorporate this into nx
so that when I run, say, nx serve api
, this flag is automatically set? Otherwise it's looking like I'll have to pivot away from nestjs and find something else which is very unfortunate.
same for me
Same issue.
Same issue here :'(
Pinging this thread in case anyone has managed to figure out a fix. Node v22 added in the experimental flag to automatically patch in support for
require()
calls in ESM graphs. This flag is--experimental-require-module
.Does anyone know how to incorporate this into
nx
so that when I run, say,nx serve api
, this flag is automatically set? Otherwise it's looking like I'll have to pivot away from nestjs and find something else which is very unfortunate.
Add the "runtimeArgs" property to the "serve" target's "options" in project.json, e.g.:
...
"serve": {
"executor": "@nx/js:node",
"options": {
"buildTarget": "api:build",
"runtimeArgs": ["--experimental-require-module"]
}
}
...
hi @mklinke it doesn't work, you have the reprod feel free to send PR if you could make it to work
Is there any workaround? This problem has been around for about 2 years now.
Is there any workaround? This problem has been around for about 2 years now.
unfortunately no, it must be supported by the nx team, hoping with the new --experimental-require-module
we could have a fix soon
@robertIsaac your solution mentioned here did not work:
https://github.com/webpack/webpack-cli/issues/2916
NX Running target serve for project nest and 1 task it depends on:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
> nx run nest:build
> webpack-cli build --node-env=production
[webpack-cli] Failed to load '/home/kasir/projects/react/apps/nest/webpack.config.ts' config
[webpack-cli] TypeError: Unknown file extension ".ts" for /home/kasir/projects/react/apps/nest/webpack.config.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:176:9)
at defaultGetFormat (node:internal/modules/esm/get_format:219:36)
at defaultLoad (node:internal/modules/esm/load:133:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:570:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:445:45)
at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Warning: command "webpack-cli build --node-env=production" exited with non-zero status code
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
NX Running target serve for project nest and 1 task it depends on failed
Failed tasks:
- nest:build
Now I am asking myself why in the world Nx decided to use webpack in NestJS? It works perfectly fine without it ๐ข.
JFI: When I decided to just go back to CommonJS since it was not a deal breaker for me I realized that hell yeah, there is a murder case here: NX Daemon is not running. Node process will not restart automatically after file changes.
. So now I do not have hot reload in my NestJS app (do the manual restart yourself) ๐.
So I got it working with ESM on my machine but it is practically not usable in real life projects: https://github.com/kasir-barati/bugs/tree/esm-nestjs-nx
Current Behavior
it fails to build/serve
Expected Behavior
it works just fine
GitHub Repo
https://github.com/robertIsaac/nx-nest-esm
Steps to Reproduce
Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
running
npx tsc --project .\apps\nx-nest-esm\tsconfig.app.json
thennode .\dist\out-tsc\apps\nx-nest-esm\src\main.js
actually works, so the problem is solely in nx doing the same for nest project produced by nest cli works without a problem, example here https://github.com/robertIsaac/nest-esm