universal-module-federation-plugin
universal-module-federation-plugin copied to clipboard
[module-federation-runtime] Warnings importing as a CommonJs module
I have a React application using Node 12, so I can not use ES modules. When I try to import the module-federation-runtime package as a Common JS module like this:
import { registerRemotes, findModule } from "module-federation-runtime/dist/node";
I get these warnings:
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
and
Error: Can’t resolve ‘module’ in ‘.../packages/widgets/node_modules/module-federation-runtime/dist/node
The warning critical dependency is correct, just ignore it, the reason is the code in dist/node :
"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:require
Error: Can’t resolve ‘module’
This error is because your webpackconfig.js does not have target: "node" configured. You need to first confirm whether you need to use dist/node and whether you can directly use dist/index.js
You can also send a minimum reproducible example
Error: Can’t resolve ‘module’This error is because your webpackconfig.js does not have target: "node" configured. You need to first confirm whether you need to use dist/node and whether you can directly use dist/index.js
You can also send a minimum reproducible example
I have a React app so target: node wouldn't work, and I definitely can't use dist/index.js because I'm using Node 12 which doesn't support ES modules.
This is a legacy application that I'm trying to support, so unfortunately I can not upgrade the Node version either.
dist and dist/node are both umd modules, not es modules
Isn’t the dist/index.js file an ES module? In your rollup config you have the format set to “es” (line 14).
Anyways, both the UMD module or the CJS module should work for my use case. Can you take a look at the PR that I raised to define the different entry points? It should just be an enhancement so that I can import like import … from “module-federation-runtime” instead of import … from “module-federation-runtime/dist/node/index.js”.
yes, I remember wrong. There is indeed an ES module present
the browser environment defaults to using es: dist/index, and dist/umd/index is also optional . dist/node is used by the node server environment
Although you are Node12, the ES module can still be introduced through webpack. Will there be any exceptions if you directly use the following code?
import "module-federation-runtime"