-
-
Notifications
You must be signed in to change notification settings - Fork 618
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
ESM in webpack.config.ts isn't supported if ts-node outputs ESM #2458
Comments
Temporary solution:
|
Follows #4002 Of course the instant I press "Merge" I got some new idea. This has no effect on the build size, but it should all be dropped (except the timeout) once webpack/webpack-cli#2458 is solved.
Interesting, somebody wrap code from (function (exports, require, module, __filename, __dirname) { export default {}; }()) |
Related TypeStrong/ts-node#1007, we need allow to pass |
I'll investigate it in detail tomorrow, but to be honest look like |
Sorry for delay, I think nothing to fix on our side, I am using (and everything works fine):
We need Node.js loader for From ts-node docs:
|
Here interesting case, we can |
@fregante friendly ping |
Ping for what? Are you suggesting that using |
For using |
@fregante what about:
|
I already have a way to execute it and it’s in my second comment. Ideally one should only call As far as I’m concerned, this is a webpack issue of not being able to run ESM TS config, rather than a question on how to achieve that 😅 |
Here problem on
It generates commonjs format, in my example above
My comment above should clarify that these are not really attempts to achieve, they are cardinally different things. |
Indeed, with so many moving parts I can understand that this is not strictly something that can be fixed locally.
Yes, but it generates commonjs format of the webpack config file, not webpack’s output, which is not transpiled by ts-node. In my (only) test, the webpack output is identical byte for byte. |
Yes, it is not related to
We support commonjs and ES format, so firstly we try to loader using I think you will faced with this issue in future many times for other packages with configurations. |
Came across this issue and wanted to mention a couple helpful things: Alternative to setting
Unfortunately the typescript compiler insists on converting dynamic I'm not sure if webpack has special-case logic for a CommonJS config file to return a promise, though. |
|
The tsconfig tweak I proposed is equivalent to the environment variable in that it only affects This fix may reduce confusion in these situations: TypeStrong/ts-node#1229
It's certainly not my first suggestion, and likely not relevant if All of this is ultimately working around |
FYI as of today for me to be able to import an ESM module (webpack plugin) from {
// ...
"ts-node": {
// Tell ts-node CLI to install the --loader automatically, explained below
"esm": true,
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "NodeNext",
}
},
// ... It's based on your responses above. node: v16.14.1 |
Required addional compiler options for ts-node to be able to handle ESM modules, which web-ext and web-ext-plugin now use. Also Webpack configuration needed to be split for ESLint to still be able to use it. See webpack/webpack-cli#2458 for details regarding ts-node and ESM.
Required addional compiler options for ts-node to be able to handle ESM modules, which web-ext and web-ext-plugin now use. Also Webpack configuration needed to be split for ESLint to still be able to use it. See webpack/webpack-cli#2458 for details regarding ts-node and ESM.
I still get |
@digiperfect-janak here is my full Do you have |
Thanks. I will try with the extended version of tsconfig you shared. I do have ts-node installed.
If I am not mistaken, bin/webpack.js is what is supposed to be invoked? |
in package.json:
and my tsconfig:
This solved my problem |
I think I came up with a bit more elegant solution. Simply prepend your commands referencing NODE_OPTIONS='--loader ts-node/esm' If you had "ts-node": {
"compilerOptions": {
"module": "commonjs",
"verbatimModuleSyntax": false
}
}, or something similar in your tsconfig.json, you should remove it. |
the best solution for me was: install
pay attention to the equal sign after
Node: 20.11.0 |
Describe the bug
If you use:
export default
inside it"module": "esnext"
in your tsconfig.json, or any EStype
config in package.jsonts-node will transpile the configuration into JavaScript, preserving
export default
, but the file is still being executed as CJS.ESM config files have just recently been supported (#2381, v4.5.0) but my guess is that
ts-node
or webpack is running the transpiled file outside thetype: module
directory.What is the current behavior?
To Reproduce
Steps to reproduce the behavior:
A full project is also here: refined-github/refined-github#4002
Please paste the results of
webpack-cli info
here, and mention other relevant informationThe text was updated successfully, but these errors were encountered: