Can't complete npm install when directing Docker to local NPM packages - docker

I haven’t been able to find an answer to this question anywhere, so I’m hoping someone here might have run into a similar issue.
I’m trying to containerize a NodeJS application, but run into this error during RUN npm install:
npm ERR! Could not install from "packages/example-package" as it does
not contain a package.json file
The package in question is listed as a local dependency in my app’s package.json:
"dependencies": {
"#example-name/example-package": "file:../example-package" },
There are no issues running npm install outside of docker with these local file paths.
I’ve tried copying the packages package.json file into the container, via the Dockerfile, like so:
COPY ./packages/example-package/package.json ./packages/example-package
The resulting error is:
npm ERR! Could not install "packages/example-packages" as it is not a
directory and is not a file with a name ending in .tgz, .tar.gz or
.tar
I’m at a loss as to where to go from here! Any suggestions?

You end up with a file called ./packages/example-package with the contents of the package.json rather than a directory.
You can confirm this by temporarily adding a cat of the file/dir to your Dockerfile
RUN cat ./packages/example-package
Use a / on the end of the destination path to make it a directory or specify the full path to the file.
COPY ./packages/example-package/package.json ./packages/example-package/
COPY ./packages/example-package/package.json ./packages/example-package/package.json

Related

I tried to install Pupilfirst LMS

I tried to install Pupilfirst LMS, I had difficulty in step
Compile Rescript Code: yarn run re: build
Output: Usage Error: could't find a script named "re: build".
And I also have difficulty in step
Run Webpack Dev Server: yarn run wds
Output: Usage Error: could't find a script named "wds".
is there any solution?
https://docs.pupilfirst.com/developers/development_setup
There shouldn't be a space between re: and build: yarn run re:build.
Also, when running a yarn run script_name command, make sure that your current directory contains a package.json file where the script script_name is defined.
In case of pupilfirst this file is in the root: https://github.com/pupilfirst/pupilfirst/blob/e41ffb8a57f4c59f7927056af324b5c283fb0038/package.json

How can I install a local package in a docker container?

I have two local (custom) NPM packages that I've used before. When I install them with npm i parentFolder/package1 parentFolder/package2, they install just fine. However, when I add them to my package.json file, and then copy / npm install in my DockerFile, I get an error saying "Could not install from "x" as it does not contain a package.json file.". I honestly don't know what to make of this, since it does have a package.json file, and it installs just fine otherwise.
Is there a special step that I need to take for custom packages to work in docker, or am I just lost somehow? I've been staring at this error so long that my brain's a mess, so I probably forgot to add some details. If I forgot something you need to know in order to help, please let me know.
Docker-compose file:
volumes:
- ./sprinklers:/app
# - sprinklers_node_modules:/app/node_modules/
- ./sprinklers/node_modules_temp:/app/node_modules/
# - sprinklers_persistent:/app/.node-persist/
- ./sprinklers/.node-persist:/app/.node-persist/
As you can see, I was using named volumes, but tried going to mounted ones to see what happened.
DockerFile:
FROM node:14.16.0-slim
WORKDIR /app
RUN npm install
The COPY statements here were removed, since all files are mounted in the docker-compose file.

Explanation and best practise around yarn - warning Integrity check: System parameters don't match

When I was building and trying to run my docker image with a rubyonrails app, I was getting this error:
warning Integrity check: System parameters don't match
error Integrity check failed
error Found 1 errors.
I tried changing my Docker file with
RUN yarn install --check-files
But that didn't do anything.
I then just deleted the yarn.lock file and my container now runs.
I am guessing the issue is that rails was run locally on my laptop, and now it is trying to run the same yarn.lock file on another computer and the integrity check is failing? Is this correct?
What should my dockerfile be doing? Should I exclude the yarn.lock file from getting into my docker container in the first place?
First of all, you will need to remove the node_modules folder and run the yarn install again. In your command line, follow these instructions:
Remove node_modules folder by typing rm -rf node_modules
Run yarn install
Run rails webpacker:install
Restart your command-line editor.
Be careful about the NodeJS version in your machine. It must be the same as the version in which the rails project was initialized. You can use nvm to manage the Node version.
Add "config.webpacker.check_yarn_integrity = false" in "development.rb" will solve the problem
I would suggest not copying yarn.lock in the container. You can add yarn.lock in the .dockerignore which Docker will ignore the yarn.lock while building the image.
I had faced similar issues because, locally I run on macOS and containers are alpine-based, so we end up ignoring the yarn.lock

NPM browserstack alias installed by package.json for TestCafe not recognized

Installing 'testcafe-browser-provider-browserstack' by package.json causes Jenkins job not to recognize 'browserstack'
Tried removing from package.json and install from command line but dependencies cause npm install to error.
testcafe 1.1.4
testcafe-browser-provider-browserstack 1.8.0
npm install
node_modules/.bin/testcafe -e browserstack:safari auth-subscriber-access-myaccount.js
ERROR Unable to find the browser. "browserstack:safari" is not a browser alias or path to an executable file.
One way to debug the issue would be to run the test explicitly with your BrowserStack credentials with the following command -
BROWSERSTACK_USERNAME="YOUR_USERNAME" BROWSERSTACK_ACCESS_KEY="YOUR_KEY" testcafe "browserstack:safari#12.0:OS X Mojave" "path/to/test/file.js"
I tried different paths and also moving to devDependencies in package.json but wasn't successful. I removed from package.json and installed command line at run time and it works.
Maybe I didn't find the right path to call it or it needs to be "local" installed but it now recognizes 'browserstack' this way.

Build executable for windows with Vue CLI Plugin Electron Builder in linux

I'm trying to build an executable file for windows from my linux but so far I have not been able to do it.
According to the documentation, it tells me that here I could configure, for example, the output folder.
pluginOptions: {
electronBuilder: {
outputDir: 'desktop-for-windows',
},
},
and if it works but does not say anything about how to change the platform (s.o) to build.
also try testing the following command:
npm run electron:build --win
but by default it builds for linux
Ran into same thing trying to move from an older boiler plate to using Vue-CLI 3 just now.
Run this from within the project directory and see if it works:
./node_modules/.bin/vue-cli-service electron:build --windows
I got the --windows from the ui.js file in the vue-cli-plugin-electron-builder directory under node_modules. Other options are --linux and --macos. I'm surprised I don't see a --all flag or that all isn't the default.
If you add "build:win": "vue-cli-service electron:build --windows" under scripts in your package.json then you can instead run npm run build:win from there on.
I just faced the same problem and found pretty easy answer.
You can just run npm run electron:build -- --linux deb --win nsis in the project directory.
There is more about it here: https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#multi-platform-build

Resources