Local NPM dependency in package.json not installing

I forked an NPM package and included it in the root directory of my source code (./dependencies/module-name)

I added in my package.json as:
“module-name”: “file:dependencies/module-name”

It works locally, but when deploying on Netlify, it doesn’t work and can’t find the module-name in the app.

Any ideas?

Thanks a lot!

Hiya @Migs86 and welcome to the community! Sorry it took us a few days to get back to you.

Could you check out this debugging guide, and at a minimum, answer the questions at the end? being able to see your build logs will be step one for our troubleshooting, once you’ve confirmed that things work locally from a clean copy of the repo, and that you’ve got the same versions configured here as you use locally:

Same problem here.
I had a local dependency (working 15 days ago) installed like:

// package.json
"@bit/my-component": "file:./bit/my-component"

But the build progress errors out:

Can't resolve '@bit/my-component' in file.js

It works locally and not in production. I did all the steps. It seems that the /node_modules folder does not have the package installed in build step.

Hey there, thanks for reaching out.

Can you give this a read through and let us know if that fixes the issue?

I (kind of) solved the issue.

The package was missing because the /dist folder was not present. So I had to remove the /dist folder from the .gitignore from one of the private npm packages.

But this is a workaround (Uploading the bundled resulting package from a private registry),

I cannot add the bit.dev private .npmrc. Even following these instructions.

Nor this instructions:

You could probably create the folder as part of your build command instead of committing it if the issue was only that it needs to exist.

With regards to your other issue, can you provide more information on what error you are running into when following the instructions you linked to? What does your .npmrc look like? Do you have a deploy link of this failing to deploy? Not knowing your results really prevent me from making any useful advice, at this time.

Let me know if you have any other questions.

Was there any resolution here? This problem is the same for me, where Netlify doesn’t resolve local file packages as dependencies when running the node build command.

In other words,

when you have a package.json that defines a dependency from your file system as appears to from git, etc “file:/…/path/to/local/package” it won’t resolve properly.

The file is part of my repository, and when I build locally it runs fine. But when it try’s to install and build during a Netlify deploy it can’t resolve those packages.

could you show us your package.json please? it sounds odd that this wouldn’t work.

I have the same issue - local dependency cannot be resolved

"typescript-axios": "file:gen/api_client",

I get
12:37:33 AM: ModuleNotFoundError: Module not found: Error: Can’t resolve ‘typescript-axios’ in ‘/opt/build/repo/src/pages’

the directory gen/api_client is commited

can you post your package.json please?

@perry thanks here is the package.json

{
 "name": "front",
 "scripts": {
   "dev": "rm .env & next dev",
   "build": "next build"
 },
 "dependencies": {
   "@adyen/adyen-web": "^3.20.0",
   "@fortawesome/fontawesome-svg-core": "^1.2.28",
   "@fortawesome/free-solid-svg-icons": "^5.13.0",
   "@fortawesome/react-fontawesome": "^0.1.9",
   "axios": "^0.20.0",
   "calendar-link": "^2.0.4",
   "chart.js": "^2.9.4",
   "cookies": "^0.8.0",
   "http-proxy": "^1.18.1",
   "i18n": "^0.13.2",
   "leaflet": "^1.6.0",
   "moment": "^2.29.1",
   "next": "10.0.3",
   "next-images": "^1.4.0",
   "nextjs-progressbar": "0.0.5",
   "nouislider-react": "^3.3.7",
   "react": "^16.14.0",
   "react-big-calendar": "^0.29.0",
   "react-chartjs-2": "^2.11.1",
   "react-color": "^2.19.3",
   "react-cool-onclickoutside": "^1.5.9",
   "react-copy-to-clipboard": "^5.0.2",
   "react-dates": "^21.8.0",
   "react-dom": "^16.13.1",
   "react-dropzone": "^11.0.1",
   "react-id-swiper": "^3.0.0",
   "react-image-lightbox": "^5.1.1",
   "react-joyride": "^2.3.0",
   "react-leaflet": "^2.7.0",
   "react-phone-input-2": "^2.13.9",
   "react-scroll": "^1.7.16",
   "react-select": "^3.1.0",
   "react-share": "^4.3.1",
   "react-syntax-highlighter": "^12.2.1",
   "react-timekeeper": "^2.1.3",
   "reactstrap": "^8.4.1",
   "sass": "^1.26.3",
   "swiper": "^5.3.8",
   "typescript-axios": "file:gen/api_client",
   "use-places-autocomplete": "^1.6.1",
   "zlib": "^1.0.5"
 },
 "browserslist": [
   ">= 1%",
   "last 1 major version",
   "not dead",
   "Chrome >= 45",
   "Firefox >= 38",
   "Edge >= 12",
   "Explorer >= 10",
   "iOS >= 9",
   "Safari >= 9",
   "Android >= 4.4",
   "Opera >= 30"
 ],
 "devDependencies": {
   "@openapitools/openapi-generator-cli": "^2.0.3"
 }
}

hi there, i think the typescript-axios should be a dev dependency, not a regular one, as it is needed at build time. Can you move it to dev dependencies and see if that works better?

Hi @perry thank you for your help - unfortunately, moving the dependency to devDependencies yields the same error…

Hi, @villqrd. The dependency in question is not a remote dependency. It is a local directory:

"typescript-axios": "file:gen/api_client",

Is gen/api_client committed to your repo? If not, Netlify has no way of accessing it because it isn’t public or in the repo.

@luke @perry

I recloned my repo and tried to build locally from fresh and it failed with the same error.

The issue is that the node_modules directory inside gen/api_client was obviously not commited (in .gitignore) so I have to add the command to go inside the gen/api_client folder and run “npm install && npm run build” and it works!

Thanks again for support and I hope this will help others

1 Like