When I run next dev
on this project I get the following kind of errors. They are all caused by one internal library required by other internal libraries as dependency:
Module not found: ESM packages (@company/style-lib) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals
Pointing to this kind of line:
var style_lib_1 = require("@company/style-lib");
Which is inside this path:
./node_modules/@company/another-component-library/node_modules/@company/utils-lib/lib/cjs/components/Component/Component.js:51:0
So, it's a deeply embedded dependency that I can't change the import/export logic of. The strange part is that same project runs without issues on other teammates local environments. Also it used to run fine at one point on my Windows machine, until this error appeared. Worked fine on MacOS locally for a long time, until yesterday - until same issue appeared for what looked like no reason (no major project setup changes).
I tried (without any success) multiple times deleting node_modules
, yarn.lock
, cleaning npm cache and running again.
Also tried adding this to next.config.js
experimental: {
transpilePackages: ['@company/style-lib'],
esmExternals: true,
},
I tried to debug by replacing all require
statements with import
ones, which just yielded this kind of errors:
TypeError: (0 , _company__style_lib__WEBPACK_IMPORTED_MODULE_3__.styled) is not a function
This is module setup from package.json
of style-lib
:
{
"module": "dist/index.mjs",
"type": "module",
...
}
The main project uses volta
for node/yarn versions:
"volta": {
"node": "16.13.1",
"yarn": "1.22.17"
}
Please let me know what kind of additional info could be helpful for solving this issue.