2

I am using "firebase-functions": "^3.6.0", "firebase-tools": "^8.0.0" to deploy my Angular: 10.0.14 app. All was working fine until I decided to move some components into a library created using the command ng generate library and made the package a submodule in my project under ./projects/my-lib

I build the lib using ng build my-lib

Then in my package.json installed the lib from file

"my-lib": "file:dist/my-lib"

I installed the package locally and it works fine when I test it locally but deploying using ng deploy raised the error

npm ERR! Could not install from "dist/mce-lib" as it does not contain a package.json file.

I have tried a couple of solutions I found online, but no luck yet

theTypan
  • 5,471
  • 6
  • 24
  • 29

3 Answers3

7

Try this

First, remove node_modules and package-lock.json file

rm -rf node_modules package-lock.json

Then, clean cache

npm cache clean --force

And last re-install modules

npm i
Usama Majid
  • 1,103
  • 13
  • 13
0

You need to create the library by using

  ng generate library <your lib name>

This will setup your lib with the necessary files so that you can add it as a dependency.

Otherwise, if you want to do this manually it'll require more work.

UPDATE:

To be able to use the lib above locally without publishing you will need to do the following

From withing your app directory for which you generated the lib, go into ./projects/ as it was generated by the lib command above. Then run the following build command

  ng build <your lib name> --prod

The prod tag is optional but it helps to run your code in that flag so that it is the closest to what it will look like once you publish

Then go back to your app root folder and install the application by referencing the dist folder. The build command above should have added your lib as its own folder withing dist

  npm install ./dist/<your lib name>

NOTE: All of this is for dev testing purposes. Ideally, you will want to publish your lib to npmjs or github packages first and then install it properly in your app before you deploy your app to production

Another way of locally: though the use of npm link

   cd ./dist/<your lib name>
   npm link

Then going back to root folder of app, you should be able to run the installation as such

  npm link <your lib name>

This creates a local link to your library in your app for testing purposes that doesn't modify your package.json file as installing the directory directly does. Once you are done, always make sure to run unlink

 npm unlink <your lib name>

And withing your ./dist/

 npm unlink

 
Edward Romero
  • 2,905
  • 1
  • 5
  • 17
  • 2
    You should add what you have tried to avoid confusion then... –  Sep 06 '20 at 17:12
  • @theTypan I think you're probably missing some steps. Check out above update as I have provided step by step on how I have done this in the past – Edward Romero Sep 06 '20 at 17:25
  • @EdwardRomero Thanks again..I have tried your steps but it did not work – theTypan Sep 06 '20 at 18:43
  • @theTypan that's very odd. Can you update the question above with your apps directory structure. That's the only other thing that I can think is messed up when creating your lib, that causes the steps above to not worked properly. The idea is for us to be able to see your app, and the location of the lib you created to make sure your repo is setup properly – Edward Romero Sep 06 '20 at 19:43
  • @EdwardRomero I posted my own answer, Thanks a lot...I really appreciate – theTypan Sep 07 '20 at 08:32
0

So after hours of trying to figure out how to solve this, I came across these resources that helped me to resolve the issue:

https://firebase.google.com/docs/functions/handle-dependencies#including_local_nodejs_modules_as_part_of_your_deployment_package

Note: The Firebase CLI ignores the local node_modules folder when deploying your function.

Firebase Functions local "file:" dependencies

So even if the app was working locally, the node_modules isn't deployed

Since I had installed python packages from git before, I thought why not make use of this? I am using Gitlab and this answer really helped me https://stackoverflow.com/a/50314604/3247914

I got it working by installing my package from git

theTypan
  • 5,471
  • 6
  • 24
  • 29