NX NodeJs App build Error: Can't import the named export 'someThing' from non EcmaScript module (only default export is available)

Note Statistics

Note Statistics

  • Viewed 487 times
Thu, 09/16/2021 - 16:17

This error occurs when building an NX node (@nwrl/node) app. This error is related @nrwl/node (^12.9.0) that uses Webpack 4 now, which tries to load .mjs by default.


1. Create a custom webpack file for you node project

module.exports = (webpackConfig) => {
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto",
    return webpackConfig;

Reference this file in the workspace json

In the workspace json , update the build config of your project. To do this, set the webpackConfig build option to point to the target Webpack file.

Option path:

projects.<your project name>.build.options.webpackConfig


				"webpackConfig": "apps/example-app/webpack.config.js"
Authored by