I'm currently developing a Next Js application that utilizes its mongoose models from a local npm package, allowing for shared functionality across different backend components. However, I am encountering the following errors:
Module not found: Can't resolve 'supports-color' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/debug/src'
../shared-stuff/node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'
../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'
../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'
../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy/package.json' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'
../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'aws4' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'
../shared-stuff/node_modules/mongodb/lib/encrypter.js
Module not found: Can't resolve 'mongodb-client-encryption' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'
It appears that these errors are potentially caused by webpack attempting to search for dependencies of the shared-stuff
package within the my-project/app
directory instead of the designated my-project/shared-stuff
directory.
The current file structure of the project is as follows:
my-project
├── app (Next Js application with errors)
│ ├── lib
│ ├── next.config.js
│ ├── node_modules
│ ├── package-lock.json
│ ├── package.json
│ ├── pages
│ ├── public
│ └── styles
├── gather
│ ├── ecosystem.config.js
│ ├── node_modules
│ ├── package-lock.json
│ ├── package.json
│ └── src
└── shared-stuff
├── index.js
├── models
├── node_modules
├── package-lock.json
└── package.json
Contents of app/package.json
:
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"mongoose": "^6.2.6",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sass": "^1.49.9",
"shared-stuff": "file:../shared-stuff"
},
"devDependencies": {
"eslint": "^8.11.0",
"eslint-config-next": "^12.1.0"
}
}
Contents of shared-stuff/package.json
:
{
"name": "shared-stuff",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"mongoose": "^6.2.6"
}
}
One interesting observation is that although both packages only have mongoose
as a dependency, the shared-stuff/node_modules
folder contains a mongodb
directory while the app/node_modules
does not.
Another package located in the gather
directory also lists shared-stuff
as a dependency but operates without issues due to the absence of webpack usage.
I have attempted solutions such as running npm ci
on all three projects, disabling eslint, and utilizing webpack.IgnorePlugin
in next.config.js
to ignore shared-stuff
, unfortunately without success.