I just build the dist folder of my Loopback 4 API and wish to deploy it on one of my machines.
npm run build && tar -zxvf dist.tar.gz ./dist (Move the dist.tar.gz file on another machine + untar it)
Try to run it: node ./dist/index.js
Get this error: tslib package not found.
Is there something I'm missing?
There is no packages.json in the dist folder then no way to install the dependencies... Should I add a flag or something? (I didn't find any explanation in the documentation)
In line with other TypeScript projects, LoopBack 4 projects requires dist, package.json, package-lock.json to be published.
In production, you can run this command to skip the build process and instead execute the pre-built artifacts:
node .
Related
I'm not familiar with npm so I might be holding the wrong end of the shovel here...
There is a package on npm that I would like to modify and use in my own project. The package is angular-crumbs. I forked the source repo (https://github.com/emilol/angular-crumbs) into my own account (https://github.com/capesean/angular-crumbs) and then run npm install capesean/angular-crumbs -force. However, this produces a node_modules folder in my project that hasn't been built (and whatever else - as I understand it) with the commands in the source repo's package.json file:
"build": "npm run clean && npm run transpile && npm run package && npm run minify && npm run copy"
i.e. it doesn't have the types, the correct package.json file, etc.
So my question is, how do I get the properly-built files (including type definitions, etc.) from my own repo to install or build-after-installing in my target project?
I am not sure about what you're trying to do, are trying to work on the
angular-crumbs source code, or are you trying to use it in your own project as a dependencuy ?
Anyway, running npm install will install all your dependencies so that you can directly use them in your project, those dependencies don't need to be built after they are installed.
In your case you seem to have an angular application (which is completely different from node.js), usually to start an angular app you can run ng serve which will build your source code and run an angular server so you can access it on localhost.
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
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
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
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
Is there a way to restrict npm link to create the symlink only to point at ./dist?
I am struggling so far as I want to test my library (react component) locally before publishing.
In my package.json I have included the main (entry point):
"main": "./dist/index.js"
But still when I run npm link it links to the parent folder which has node_modules and so on.
This is causing problems cause now I have 2 react apps installed.
I thought of a way to exclude node_modules but I couldn't even find a way to do that.
This is actually simpler than expected. First run ng build to build your library project, then go under the dist folder and run npm link from there instead of the library root project. The symlink will be created pointing to the dist folder instead.
Using "main" parameter doesn't make sense because npm link use 'npm prefix' for create symlink
see here
You can use next hack:
Cd to project directory
Copy package.json from package to ./dist/package.json directory
Cd to dist directory
Run 'npm link'
It looks dirty but seem to only way to do it with npm link
Created new folder and did npm install serve in it.
It created package-lock.json and node_modules/ folder.
When I run in the same folder serve it shows error:
command not found: serve
What is the way to install?
I am using: npm#6.5.0
My dev environment is MACOS
I read a great many pages on this topic and nothing worked until I tried the following
./node_modules/.bin/serve -s build
Also if you are using VS CODE you may want to bring up the terminal window outside of VS CODE - this seems to have snared a lot of people.
First of all, you should start your project running
npm init
This will create the package.json file.
Then, you can install the serve package globally.
npm install -g serve
And now you can run serve.
The serve binary was not found because the operating system cannot locate it in the PATH environment variable.
When you do the npm install serve command. The serve module is only installed into the node_modules directory found under the the project folder. Unless you explicitly include the absolute path of this node_module directory as part of your PATH env var, the OS won't know where to find serve.
Like others say, the typical practise would be to install the module using the -g flag. G means global.
When -g is used, npm will put the binary in its node directory somewhere and this this directory would have been included as part of your PATH when you install node, thus making the any new binary discoverable.
If the node.js module has a "command" and you want to run it without installing the module globally(npm install -g serve). You can run it like ./node-modules/.bin/command from the root folder of the project.
Now, what is generally used is npx, so that you can from within a project easily run any of the binaries within its local node_modules or your system's global node_modules/ and any other commands on the $PATH.
For example, here we install webpack as a local dependency. You can image doing this in a folder after running npm init. Then we run webpack without having to worry about referencing the bin file:
$ npm i -D webpack
$ npx webpack
I have built a custom npm package that is essentially a list of dependencies, a gulp file, and a configuration file for it. The idea is that I can run npm install <path-to-git-repo> to pull in gulp whenever I start a new development project.
However, I would like the gulp file and config file to be moved into the current directory, and not remain inside of node_modules. I have tried to accomplish this with the install script in my package.json file listed below, but it didn't seem to do anything. The files I'm trying to move are included in the files section of package.json.
"scripts":
{
"install": "mv gulpfile.js ./ && mv gulp.config.json ./"
},
Thanks for your help
For something like this I think it would be much easier to have 1 source gulp file and specify the dependent gulp file(s) wherever you're installing them. example blog
Also, just to point out, install is typically considered an anti-pattern
But to answer your exact question, this command mv gulpfile.js ./ && mv gulp.config.json ./ looks to me like you're saying move gulpfile.js (which is already in the root directory), into ./ (which is the same directory). Check your source directory actually contains the gulpfile.js by running the command yourself on the command line