-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
@nrwl/node application not transpiling to esm #10296
Comments
I had a similar error after running
I was missing upgrading one of my project dependencies (non-controlled by NX) to an Angular 13 supportable version. |
Have the same issue trying to use normalize-url Seems to be the same issue as: #7872 |
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. |
Up🔝 |
Same for me |
1 similar comment
Same for me |
Please annoy us via e-mail to keep it active haha In this case: Same for me |
Same thing is happening to me. Sending unicorn emojis to keep the bot from marking this issue as stale: 🦄🦄🦄🦄 |
does any one knows what was the last working version? may be its better to downgrade |
Up🔝 |
tried running the webpack builder with target: "es2021" but I got this error:
|
Up |
Instead of sending comments with up vote on the issue with 👍🏼🙄 |
@DaSchTour does that work for this repo?
|
Same for me |
I'm currently in the exploration phase of migration nestjs-apps in a nx monorepo to esm, and here are my findings so far:
my webpack-config: const { composePlugins, withNx } = require('@nrwl/webpack');
const util = require('util');
const nodeExternals = require('webpack-node-externals');
// Nx plugins for webpack.
const configFunc = composePlugins(withNx(), (config) => {
// Update the webpack config as needed here.
// e.g. `config.plugins.push(new MyPlugin())`
config.resolve.extensionAlias = {
...config.resolve.extensionAlias,
'.js': ['.ts', '.js'],
'.mjs': ['.mts', '.mjs'],
};
return config;
});
const configFuncWithOverrides = (config, ctx) => {
return configFunc(config, ctx).then((config) => {
/*
Changes here copied from https://github.com/nrwl/nx/issues/7872#issuecomment-997460397
*/
config.externalsPresets = {
node: true,
};
config.output = {
...config.output,
module: true,
libraryTarget: 'module',
chunkFormat: 'module',
library: {
type: 'module',
},
environment: {
module: true,
},
};
config.experiments = {
...config.experiments,
outputModule: true,
};
config.externals = nodeExternals({
importType: 'module',
});
return config;
});
};
module.exports = configFuncWithOverrides; |
Ok, the error I had had nothing to do with the config above, it works. The error was caused because I had a Building the app and running it works, but |
Thanks, @nidomiro! 🙏 I did everything from your list of changes, except for patching |
Working to get my entire project to esm, almost there... I have an app generated with Since it was a simple express app, I checked to see if a generated npm i --save-dev @nx/webpack Change build target in apps/myapp/project.json: "build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/myapp",
"main": "apps/myapp/src/main.ts",
"tsConfig": "apps/myapp/tsconfig.app.json",
"assets": ["apps/myapp/src/assets"],
"isolatedConfig": true,
"webpackConfig": "apps/myapp/webpack.config.js"
},
"configurations": {
"development": {},
"production": {}
}
}, Add apps/myapp/webpack.config.js: const { composePlugins, withNx } = require('@nx/webpack');
// Nx plugins for webpack.
module.exports = composePlugins(withNx(), (config) => {
// Update the webpack config as needed here.
// e.g. `config.plugins.push(new MyPlugin())`
return config;
}); I thought all was fine then very strangely(!) the error was back, (maybe from a deeper cleaning process, but no code changes). This time, hopefully finally, it was fixed by adjusting the order of imports to put the lib (from the nx workspace) after external packages from node_modules. import express from 'express';
-import { payloadFromBase58 } from '@myworkspace/mylib';
import { Encoding, Field, Poseidon, PrivateKey, Signature } from 'snarkyjs';
+import { payloadFromBase58 } from '@myworkspace/mylib'; |
…webpack :serve was failing due to an imported lib's change to esm nrwl/nx#10296 (comment)
…webpack :serve was failing due to an imported lib's change to esm nrwl/nx#10296 (comment)
Same issue here: |
This is still an issue even in the new version After playing with the tsconfig and executor of nx a bit, I think this is the main issue. Until the |
No status yet? |
About node-fetch. Hello! Maybe it's a little workaround but at this moment I don't have any other idea how to solve that. I had the same problem with node-fetch and ESModules. I'm using NestJS with Next. Three apps as monorepo and I migrate to @nrwl > @nx (16.8.1) packages. Solution is to use node-fetch2 instead of node-fetch But step by step:
As you can see nothing special with ts files and webpack. When I started to use |
This issue has been automatically marked as stale because it hasn't had any activity for 6 months. |
not stale, even if ignored😉 |
hello? please. |
1 similar comment
hello? please. |
Current Behavior
@nrwl/node application does not transpile to esm so esm-only packages (like node-fetch) fail.
Expected Behavior
Should transpile to esm
Steps to Reproduce
apps/esm-app/tsconfig.app.json
to 'esnext'tsconfig.base.json
to 'esnext'dist/apps/esm-app/main.js
should not use require() but doesmain.js contains the following at the top
Repro: https://github.com/JonNode28/nx-esm-repro
Failure Logs
Running yarn start produces the following error:
The text was updated successfully, but these errors were encountered: