Cannot run npm run wbp - asp.net-mvc

I tried to use this tutorial, to install webpack to asp.net core project
https://codeburst.io/how-to-use-webpack-in-asp-net-core-projects-a-basic-react-template-sample-25a3681a5fc2
Here is command in my package.json
{
"name": "streamline",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wbp": "webpack wwwroot/source/app.js wwwroot/dist/bundle.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.16.0",
"webpack-command": "^0.4.1"
}
}
But when I run it with npm run wbp I get this
internal/modules/cjs/loader.js:596
throw err;
^
Error: Cannot find module 'import-local'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/Users/nemesises/Documents/GitHub/streamline/Streamline/node_modules/webpack-command/lib/cli.js:11:21)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! streamline#1.0.0
wbp: webpack wwwroot/source/app.js wwwroot/dist/bundle.js npm ERR!
Exit status 1 npm ERR! npm ERR! Failed at the streamline#1.0.0 wbp
script. npm ERR! This is probably not a problem with npm. There is
likely additional logging output above.
npm ERR! A complete log of this run can be found in: npm ERR!
/Users/nemesises/.npm/_logs/2018-07-13T14_21_24_555Z-debug.log
How I can fix it?
UPDATE
After I make this
"wbp": "webpack --entry wwwroot/source/app.js --output wwwroot/dist/bundle.js"
Reinstall npm packages and try to run command
I got this error
ERROR in Entry module not found: Error: Can't resolve 'wwwroot/source/app.js' in
'/Users/nemesises/Documents/GitHub/streamline/StreamLine' npm ERR!
code ELIFECYCLE npm ERR! errno 2 npm ERR! streamline#1.0.0 wbp:
webpack --entry wwwroot/source/app.js --output wwwroot/dist/bundle.js npm ERR! Exit status 2 npm ERR! npm ERR!
Failed at the streamline#1.0.0 wbp script. npm ERR! This is probably
not a problem with npm. There is likely additional logging output
above.
npm ERR! A complete log of this run can be found in: npm ERR!
/Users/nemesises/.npm/_logs/2018-07-14T19_45_54_642Z-debug.log
But I got this file in my folder!
If I use my old command and create dist/bundle.js it works, but bundle.js is empty

webpack --entry wwwroot/source/app.js --output wwwroot/dist/bundle.js
--entry says what is the entry
--output what to output to

It seems like npm has failed to install the dependencies properly. Try to reinstall the local packages by executing the following commands in your package.json directory:
rm -rf node_modules
npm install
If everything goes fine with npm install you should be able to run npm run wbp successfully.

this worked for me: webpack --entry ./wwwroot/source/app.js --output wwwroot/dist/bundle.js, note ./ in ./wwwroot.

I'm currently digging my way into this ASP.NET CORE + Webpack + Script combo. Luckily, I've found my solution, hope this can fit your case. Take a look at my package.json
{
"name": "blindforced",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wbp": "webpack --mode production wwwroot/source/app.js --output wwwroot/dist/bundle.js",
"dev": "webpack --mode development wwwroot/assets/app.js --output wwwroot/dist/bundle.js",
"build": "webpack --mode production wwwroot/assets/app.js --output wwwroot/dist/bundle.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
}
}

Related

Mocha: Permission denied error occured in Jenkins while Integrating Playwrigh_Mocha with Jenkins via GItHub

I am trying to run Playwright_Mocha through Jenkins, so I have created a Repository in Git Hub and the same is given in Jenkins Configuration (Source Code Management).
I have given the Build Step, to run my automation script which executes as shell command "npm run aboutPage"
In which aboutPage has the script as below in package.json file.
"scripts": {
"aboutPage": "mocha --timeout 800000 --config= ./.mocharc.js ./test/aboutPage.spec.js"
}
below are the dependencies which I have installed in my project.
{
"dependencies": {
"#supercharge/fs": "^3.4.0",
"allure-commandline": "^2.18.1",
"allure-mocha": "^2.0.0-beta.19",
"chai": "^4.3.6",
"chai-dom": "^1.11.0",
"chai-jquery": "^2.1.0",
"chai-visible": "^0.1.5",
"fs-extra": "^10.1.0",
"mocha": "^10.0.0",
"mocha-allure-reporter": "^1.4.0",
"mochawesome-report-generator": "^6.2.0",
"mochawesome-screenshots": "^1.7.3",
"mysql": "^2.18.1",
"node-localstorage": "^2.2.1",
"node-sessionstorage": "^1.0.0",
"playwright": "^1.27.0",
"prettier": "^2.7.1",
"read-excel-file": "^5.5.3",
"sessionstorage": "^0.1.0",
"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"mochawesome": "^7.1.3"
}
}
When I build Jenkins, below is the error displayed in the Console Output:
npm run aboutPage
> playwright_mocha#1.0.0 aboutPage /home/qabot/data/jenkins_home/workspace/TestDemo_QA_Automation_QATAR
> mocha --timeout 800000 --config= ./.mocharc.js ./test/aboutPage.spec.js
sh: 1: mocha: Permission denied
npm ERR! Linux 4.15.0-1113-azure
npm ERR! argv "/home/qabot/.nvm/versions/node/v4.3.2/bin/node" "/home/qabot/.nvm/versions/node/v4.3.2/bin/npm" "run" "aboutPage"
npm ERR! node v4.3.2
npm ERR! npm v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! playwright_mocha#1.0.0 aboutPage: `mocha --timeout 800000 --config= ./.mocharc.js ./test/aboutPage.spec.js`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the playwright_mocha#1.0.0 aboutPage script 'mocha --timeout 800000 --config= ./.mocharc.js ./test/aboutPage.spec.js'.
npm ERR! This is most likely a problem with the playwright_mocha package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha --timeout 800000 --config= ./.mocharc.js ./test/aboutPage.spec.js
npm ERR! You can get their info via:
npm ERR! npm owner ls playwright_mocha
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/qabot/data/jenkins_home/workspace/TestDemo_QA_Automation_QATAR/npm-debug.log
Build step 'Execute shell' marked build as failure
Finished: FAILURE.
Please let me know what and where I am doing wrong.
Thanks in advance

Deploying NodeRED Docker image to Heroku fails, but local build is error free

We are trying to push a Docker image based on NodeRED to Heroku. Local build and test runs like a charm, but when we deploy it to Heroku, the Docker image build fails. Our docker file is quite simple:
FROM nodered/node-red
USER node-red
# Copy package.json to the WORKDIR so npm builds all
COPY package.json .
RUN mkdir -p node-red-static
COPY node-red-static/ node-red-static/
COPY defaults .
# NodeRED configuration
COPY .node-red/settings.js /usr/src/node-red/.node-red/settings.js
COPY .node-red/flows.json /data/flows.json
COPY package.json /usr/src/node-red/package.json
# Actual installation
RUN npm install --unsafe-perm --no-update-notifier --no-fund --only=production
(I also tried without setting the user)
The heroku.yml:
build:
docker:
web: Dockerfile
The error on git push heroku master:
npm WARN saveError EACCES: permission denied, open '/usr/src/node-red/package.json'
remote: npm WARN saveError EACCES: permission denied, open '/usr/src/node-red/package.json'
remote: npm WARN Error: EACCES: permission denied, open '/usr/src/node-red/package.json'
remote: npm WARN { [Error: EACCES: permission denied, open '/usr/src/node-red/package.json']
remote: npm WARN stack:
remote: npm WARN 'Error: EACCES: permission denied, open \'/usr/src/node-red/package.json\'',
remote: npm WARN errno: -13,
remote: npm WARN code: 'EACCES',
remote: npm WARN syscall: 'open',
remote: npm WARN path: '/usr/src/node-red/package.json' }
remote: npm WARN node-red No description
remote: npm WARN node-red No repository field.
remote: npm WARN node-red No README data
remote: npm WARN node-red No license field.
remote:
remote: audited 627 packages in 2.146s
What do I miss?
Update
The package.json
{
"name": "insect-core",
"version": "0.1.0",
"engines": {
"node": "16.1.0",
"npm": "7.9.0"
},
"main": "index.js",
"scripts": {
"serve": "node-red --settings ./.node-red/settings-development.js --userDir ./.node-red",
"start": "node-red --settings ./.node-red/settings.js --userDir /data",
"debug": "node-red --inspector --settings ./.node-red/settings.js --userDir ./.node-red",
"test": "echo \"Error: no test specified\" && exit 1"
}
"author": "techdev#protenga.com",
"license": "Apache-2.0",
"dependencies": {
"node-red": "^1.3.5",
"node-red-configurable-ping": "^1.0.1",
"node-red-contrib-auth": "^0.1.7",
"node-red-contrib-cloudantplus": "^0.3.0",
"node-red-contrib-dashboard-bar-chart-data": "^0.9.7",
"node-red-contrib-dnsquery": "^1.0.6",
"node-red-contrib-env": "^1.0.2",
"node-red-contrib-fast-csv": "^0.4.0",
"node-red-contrib-google": "^0.2.0",
"node-red-contrib-google-sheets": "^0.1.0",
"node-red-contrib-jwt": "^0.1.0",
"node-red-contrib-loop-processing": "^0.5.1",
"node-red-contrib-md5": "^1.0.4",
"node-red-contrib-moment": "^4.0.0",
"node-red-contrib-objectcleaner": "0.0.3",
"node-red-contrib-redis": "^1.3.9",
"node-red-contrib-simple-message-queue": "^0.2.7",
"node-red-contrib-simple-sendmail": "^0.1.9",
"node-red-contrib-socketio": "^1.0.7",
"node-red-contrib-uuid": "0.0.4",
"node-red-node-rbe": "^0.5.0",
"node-red-node-tail": "^0.3.1"
}
}
Just to clarify:
What fails:
heroku stack:set container
git push heroku master
which tries to build the container on heroku
What worked:
heroku container:login
heroku container:push web --app insectos
heroku container:release web --app insectos
First up, copying settings.js to /usr/app/node-red/.node-red will do nothing as it will be ignored. The usrDir for the Node-RED Docker container is /data so the settings.js needs to be copied to there.
Second, to install extra nodes add them to the package.json in /data not /usr/src/node-red. Then run npm install ... in the /data directory, this will install the nodes into /data/node_modules.
If you want to remove any of the core nodes then you need to included their filenames in the nodesExcludes key in the settings.js as follows:
...
nodesExcludes: [ '90-exec.js', '10-file.js'],
...

React - Docker Syntax Error: Unextpected token

I have a react app which starts outside of Docker but not inside.
I'm running a backend Node app which works in Docker, this failing front-end is the issue. From previous threads and questions i'm certain it is not the 'globby' module at fault, it's likely to be my config or installation.
The error:
react-scripts start
/usr/src/app/node_modules/react-dev-utils/node_modules/globby/index.js:49
...taskOptions
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/src/app/node_modules/react-dev-utils/globby.js:10:14)
npm info lifecycle react-frontend#0.1.0~start: Failed to exec start script
npm ERR! Linux 4.19.128-microsoft-standard
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.11.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! react-frontend#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
My Dockerfile
FROM node:6.11.1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
My package.json
{
"name": "react-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"globby": "^11.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "^4.0.1",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
What i've tried:
deleting node_modules and redoing npm install
Docker rebuilds
After #vpalmerini pointed out the Node version, I updated to 14.15.4-alpine and ran
docker-compose build
docker-compose up
So now my Dockerfile contains
FROM node:14.15.4-alpine
The app is now running as expected.

Why the docker node container doesn't find local files in the docker volume?

I try to run a web app from local files in a node container. To do so, using PowerShell, I go to the app root folder and I run
PS C:\my_local_dir> docker run -p 8080:4200 -v ${pwd}:/www -w "/www" node npm start
and this is the output I get:
npm ERR! path /www/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/www/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
I can confirm that the file package.json is present, and that running npm start in this folder works.
Inspecting the container with docker inspect:
(...)
"Mounts": [
{
"Type": "bind",
"Source": "/host_mnt/c/my_local_dir",
"Destination": "/www",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
(...)
What's wrong in my command ?
By the way I got the command from this PluralSight course

.npmrc registry settings is not used by npm install

I working behind a proxy and therefore I use a local npm registry in nexus.
I have an .npmrc config with the registry settings in jenkins:
/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs-default/bin/node "/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs-default/bin/npm" config get registry
https://nexus/repository/npm-all/
When I want to run npm install I get the following error:
/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs-default/bin/node "/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs-default/bin/npm" "install"
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t git://github.com/ariya/esprima.git
npm ERR!
npm ERR! fatal: unable to connect to github.com:
npm ERR! github.com[0: 192.30.253.113]: errno=Connection refused
npm ERR! github.com[1: 192.30.253.112]: errno=Connection refused
npm ERR!
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-03-29T13_46_39_199Z-debug.log
Why it want to connect to github.com instead of nexus? It is second run of npm install, the first install downloads some packages from nexus but when it want to download ariya/esprima it stops with the same error.
My package.json: (it is an old build)
{
"name": "my-application",
"version": "1.0.0",
"devDependencies": {
"autonumeric": "^1.9.39",
"bootbox": "^4.4.0",
"bootstrap": "^3.3.5",
"bootstrap-datepicker": "^1.4.1",
"bootstrap-tour": "^0.10.1",
"chalk": "^1.0.0",
"file-sync-cmp": "^0.1.1",
"font-awesome": "^4.4.0",
"grunt": "^0.4.5",
"grunt-auto-install": "^0.2.4",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-copy": "^0.8.0",
"grunt-replace": "^0.10.2",
"grunt-ts": "^4.2.0",
"grunt-tsd": "^0.1.0",
"i18next": "^1.9.0",
"i18next-client": "^1.9.0",
"jquery": "^2.1.4",
"jquery.cookie": "^1.4.1",
"jquery.scrollto": "^2.1.1",
"knockout": "^3.3.0",
"moment": "^2.10.3",
"qunit": "^0.7.6",
"require": "^2.4.18",
"requirejs": "^2.1.18",
"typeahead.js": "^0.11.1"
},
"dependencies": {
"grunt-cli": "^1.2.0"
}
}

Resources