npm packages using local paths are not supported.
michalczaplinski opened this issue · 3 comments
Describe the bug:
The runtime does not support local npm packages using the "packageName": "file:./package"
syntax.
Link to the blitz that caused the error:
https://stackblitz.com/edit/node-5ppqi3
Steps to reproduce:
npm install
node index.js
Error: Cannot find module '/projects/node-5ppqi3/node_modules/test-package/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:178912)
at Function.Module._findPath (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:180576)
at Function.Module._resolveFilename (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:185323)
at Function.Module._load (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:183130)
at Module.require (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:186304)
at i (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:484674)
at _0x1cc684 (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:11:20414)
at Object.eval (/projects/node-5ppqi3/index.js:2:14)
at Object.function (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:11:20499)
at Module._compile (https://node-5ppqi3.jw.staticblitz.com/blitz.57be275669708b1d42e233d60c80159bef577631.js:6:187549) {
code: 'MODULE_NOT_FOUND',
path: '/projects/node-5ppqi3/node_modules/test-package/package.json',
requestPath: 'test-package'
}
Expected behavior:
Should run successfully
Desktop (please complete the following information):
- OS: MacOS
- Browser: chrome
- Version: 90
Hey!
You are right. This syntax is indeed not supported at this point. We do have this on our roadmap but might not be implemented in the near future. I will add this to our internal issue tracker so we def keep tracking it!
Until this is fixed, a possible workaround is to use workspaces
.
For example, if your local dependencies are in the packages
folder, like this:
{
"dependencies": {
"my-package": "file:./packages/my-package"
}
}
You can make StackBlitz install them correctly by adding:
{
"workspaces": [
"packages/*"
]
}
With a small caveat: it doesn't work if you only have local dependencies. You need to have at least one external dependency:
{
"dependencies": {
"my-package": "file:./packages/my-package",
"dependency": "0.0.1"
}
}
Also, you probably need to remove both node_modules
and package-lock.json
before running npm install
again.
This is the example that @michalczaplinski shared, but working now: https://stackblitz.com/edit/local-packages-node-example
This issue has been fixed.