I get the following error when running npm build - node.js

{
"name": "confusion",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"bootstrap-social": "^5.1.1",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"lite-server": "^2.4.0",
"popper.js": "^1.12.9"
},
"devDependencies": {
"cssmin": "^0.4.3",
"htmlmin": "0.0.7",
"node-sass": "^4.7.2",
"onchange": "^3.3.0",
"parallelshell": "^3.0.2",
"rimraf": "^2.6.2",
"uglifyjs": "^2.4.11",
"usemin-cli": "^0.5.1"
},
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\"",
"clean": "rimraf dist",
"copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/fonts",
"imagemin": "imagemin img/* -o dist/img",
"usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html",
"build": "npm run clean && npm run imagemin && npm run copyfonts && npm run usemin"
}
}
C:\Users\username\Documents\coursera\Bootstrap4\conFusion>npm run build
> confusion#1.0.0 build C:\Users\username\Documents\coursera\Bootstrap4\conFusion
> npm run clean && npm run imagemin && npm run copyfonts && npm run usemin
> confusion#1.0.0 clean C:\Users\username\Documents\coursera\Bootstrap4\conFusion
> rimraf dist
> confusion#1.0.0 imagemin C:\Users\username\Documents\coursera\Bootstrap4\conFusion
> imagemin img/* -o dist/img
4 images minified
> confusion#1.0.0 copyfonts C:\Users\username\Documents\coursera\Bootstrap4\conFusion
> copyfiles -f node_modules/font-awesome/fonts/* dist/fonts
> confusion#1.0.0 usemin C:\Users\username\Documents\coursera\Bootstrap4\conFusion
> usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html
undefined:1625
throw new JS_Parse_Error(message, filename, line, col, pos);
^
SyntaxError: Unexpected token: punc ({)
at JS_Parse_Error.get (eval at <anonymous> (C:\Users\username\Documents\coursera\Bootstrap4\conFusion\node_modules\usemin\node_modules\uglify-js\tools\node.js:27:1), <anonymous>:86:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 usemin: `usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 usemin 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! C:\Users\username\AppData\Roaming\npm-cache\_logs\2018-09-24T21_38_01_183Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 build: `npm run clean && npm run imagemin && npm run copyfonts && npm run usemin`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I am doing the same course and had the same errors. However, I was just able to fix it. I did this by reinstalling all dev dependencies and used the current versions, not the ones in the course.
I did also change the usemin command (according to the post here) to
"imagemin": "imagemin img/* --out-dir=dist/img",
However, it still did not work, so I checked all my files for errors using the following tools:
https://www.freeformatter.com/java-regex-tester.html for testing the html files; http://www.webtoolkitonline.com/javascript-tester.html, for testing the .js file and https://jsonlint.com/?json=, to test the package.json file for errors.
After I did correct all the files, the command "npm run build" did finally work. (I especially forgot to check the script.js file where I just copied the code from the html file that still contained the script tags)

You're probably using ES6 syntax but ES5 presets.
Add the babel-preset-es2015 dependency to fix this.
And also add 'es2015' in .babelrc file.
json
{
"presets": ["es2015"]
}

Follow the GitHub page of imagemin, it has the solution:
https://github.com/imagemin/imagemin-cli
Replace
"imagemin": "imagemin img/* -o dist/img",
with
"imagemin": "imagemin img/* --out-dir=dist/img",

the issue might be in your scripts.js file but first, try to do the
next test, step by step.
from your package.json ... change
"imagemin": "imagemin img/* -o dist/img",
to
"imagemin": "imagemin img/* --out-dir dist/img/",
and change (only add another *.html file, but now we'll trying with only one *.html file)
"usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html",
to
"usemin": "usemin contactus.html -d dist -o dist/contactus.html --htmlmin true",
if doesn't work, keep the changes and try this
from your *.html ... change
<!-- build:js js/main.js -->
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/tether/dist/js/tether.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
<!-- endbuild -->
to
<!-- build:js js/main.js -->
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/tether/dist/js/tether.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- endbuild -->
<script src="js/scripts.js"></script>
run
npm run usemin
if see your dist folder and the complete path with css and js
folders and html files; the conclusion is, you need to check the
syntax of JavaScript from you scripts.js file.

I stuck to that error too for the same course task.
I was just able to fix it by only reinstalling usemin-cli, cssmin, uglify-js and htmlmin dev dependencies by the current versions without specify any by :
sudo npm install --save-dev usemin-cli cssmin uglify-js htmlmin
then
npm run build
then I found all the files including html which make the usemin problems inside dist folder.

Maybe it the error with the version try writing
npm install -g imagemin-cli
instead of
npm install -g imagemin-cli#"version"

I am running the same course, and after read, and search, I realize scripts.js is the winner, currently, the code looks like this:
$(document).ready(()=>
...
Just need to change to this:
$(function(){
...
Please, refer to jquery documentation :jQuery official

Thanks man, I was facing the same issues,
What i did is,
I ran individual components starting from imagemin. I had an error with it so I ran
sudo npm install imagemin imagemin-cli
next i ran usemin, and with individual html, i found that except index rest all htmls were fine so I used a html validator and found some errors in the html i fixed those errors and now everything worked.

Related

Node.js app runs locally but fails on docker (sh: 1: rimraf: not found)

I am able to build the docker image but can't get the container to run. Here is the package.json:
{
"name": "linked-versions-viewer",
"version": "1.0.0",
"description": "...",
"main": "./dist/bundle.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf dist",
"build_only": "rollup -c",
"build": "cross-env NODE_ENV=production npm run clean && npm run build_only",
"serve": "parcel src/index.html --port 12345",
"start": "npm run clean && npm run serve"
},
"repository": {
"type": "git",
"url": "..."
},
"author": "...",
"license": "...",
"dependencies": {
"antd": "^4.12.3",
"base-widget": "...",
"react": "^17.0.2",
"react-dom": "^17.0.1"
},
"devDependencies": {
"#types/node": "^14.14.28",
"#types/react": "^17.0.2",
"#types/react-dom": "^17.0.1",
"cross-env": "^7.0.3",
"parcel-bundler": "^1.12.4",
"rev-hash": "^3.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.39.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"rollup-plugin-uglify": "^6.0.4",
"typescript": "^4.1.5"
}
}
Here is the dockerfile:
FROM node:14.17.0 as base
ENV NODE_ENV=production
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
FROM base as production
ENV NODE_PATH=./build
CMD ["npm", "start"]
I created the image by running docker build -t testapp . and tried running the container with docker run -p 8080:8080 -d testapp but it keeps immediately exiting with code 1. This is the error log for the image:
> linked-versions-viewer#1.0.0 start /app
> npm run clean && npm run serve
> linked-versions-viewer#1.0.0 clean /app
> rimraf dist
sh: 1: rimraf: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! linked-versions-viewer#1.0.0 clean: `rimraf dist`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the linked-versions-viewer#1.0.0 clean 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! /root/.npm/_logs/2021-06-09T20_40_17_204Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! linked-versions-viewer#1.0.0 start: `npm run clean && npm run serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the linked-versions-viewer#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I tried just removing the rimraf dependency altogether but then got a similar error for the parcel dependency, so maybe the packages aren't being installed properly? The app is also written in typescript if that's helpful.
Not sure what to try next. Thank you for any suggestions.
Form npm install docs,
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies
Since you have ENV NODE_ENV=production in your base image, neither rimraf nor parcel-bundler is installed inside your container.
Your npm start command is running npm run clean && npm run serve. npm run clean uses rimraf module and npm run serve uses parcel-bundler module. This is the reason why you're seeing both the errors.
You can try one of the following solutions,
Remove ENV NODE_ENV=production from your Dockerfile (This is the quickest solution but should not be used in production)
You can install rimraf and parcel-bundler globally inside the container using:
RUN npm install --global rimraf && npm install --global parcel-bundler
However, I still don't think this is a good production-ready setup.
You can properly build your app using npm run build inside your container and serve it. However, I am not familiar with React enough to help you set up this on Docker.

NPM Build issue

Trying to run this command: npm run build.
Here is the scripts definition of the package.json file
"scripts": {
"start": "npm run build",
"build": "webpack -d, --devtool && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
"build:prod": "webpack -p && cp src/index.html dist/index.html"
},
"keys": [
"reactjs"
],
This is the error been produced regardless I also tried for build in scripts webpack -d, wepack -d --devtool as well webpack -d, --devtool nothing helped. The error shows as
[webpack-cli] Error: Option '-d, --devtool ' argument missing
[webpack-cli] Run 'webpack --help' to see available commands and options
npm ERR! code 2
npm ERR! path /Users/naveed.hasan/Projects/demo/react/fileuplod
npm ERR! command failed
npm ERR! command sh -c webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
you should configure the devtool option, either in the command line -d eval or in your webpack.config.js file :
module.exports = {
...
devtool: 'eval',
...
};
You have a comma after your -d in your script:
"build": "webpack -d, --devtool
-----------------------------^ there
I'm not a webpack user, but it doesn't look voluntary

sh: 1: del: not found

I'm wondering if you can help me
Failed Heroku deploy. Been looking at other similar stack overflow posts and changing package.json file trying solutions that have worked for others with no luck. I don't think this is a port issue but it could be a package.json issue or something completely different. Any help, tips or advice is greatly appreciated!
Heroku Log:
-----> Build
Running build
> honeyman-designs#1.0.0 build /tmp/build_a9c0d0bf
> del dist && babel backend -d dist && cd frontend && npm install && npm run build
sh: 1: del: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! honeyman-designs#1.0.0 build: `del dist && babel backend -d dist && cd frontend && npm
install && npm run build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the honeyman-designs#1.0.0 build 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! /tmp/npmcache.tyCCY/_logs/2020-12-31T15_09_59_938Z-debug.log
This is my package.json file:
{
"name": "honeyman-designs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.10.15",
"react-paypal-button-v2": "^2.6.2"
},
"devDependencies": {
"#babel/cli": "^7.12.1",
"#babel/core": "^7.12.3",
"#babel/node": "^7.12.1",
"#babel/preset-env": "^7.12.1",
"nodemon": "^2.0.6"
},
"scripts": {
"start": "nodemon --watch backend --exec babel-node backend/server.js",
"build": "rd /s dist && babel backend -d dist && cd frontend && npm install && npm run build",
"heroku-postbuild-x": "npm run build && cd frontend && npm install && npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/codegreene93/HoneymanDesigns.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/codegreene93/HoneymanDesigns/issues"
},
"homepage": "https://github.com/codegreene93/HoneymanDesigns#readme",
"engines": {
"node": "12.4.0",
"npm": "6.14.10"
}
}
I have tried clearing cache and deleting and reinstalling node_modules and package-lock.json
I've updated the node and npm version
I'm using Windows 10 and I've also tried it like this:
del dist && babel backend -d dist && cd frontend && npm install && npm run build
rd /s dist && babel backend -d dist && cd frontend && npm install && npm run build
rm -r dist && babel backend -d dist && cd frontend && npm install && npm run build
None of them run get the same sh:1 error
server.js file:
app.listen(config.PORT, () => {
console.log('Server started at http://localhost:5000');
});
config.js
PORT: process.env.PORT || 5001
rd and del are Windows commands, but Heroku doesn't run Windows. You won't be able to use those commands on Heroku.
I suggest using a cross-platform alternative like rimraf insted of platform-specific commands so your scripts will run properly on your local development environment as well as your hosted environment.
Add it to your dependencies and then use something like
npx rimraf dist && babel backend -d dist && cd frontend && npm install && npm run build

npm run build error when running "npm run build"

Getting error when running npm run build:
Can any one help me to fix this issue.
Package.json file:
{
"name": "confusion",
"version": "1.0.0",
"description": "This is a website for Ristorante Con Fusion",
"main": "index.html",
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\"",
"clean": "rimraf dist",
"copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/fonts",
"imagemin": "imagemin img/* --out-dir=dist/img",
"usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html",
"build": "npm run clean && npm run imagemin && npm run copyfonts && npm run usemin"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cssmin": "^0.4.3",
"htmlmin": "0.0.7",
"lite-server": "^2.5.4",
"micromatch": "^4.0.2",
"node-sass": "^4.14.1",
"onchange": "^3.3.0",
"parallelshell": "^3.0.1",
"rimraf": "^2.6.2",
"uglify-js": "^3.11.6",
"usemin-cli": "^0.6.0"
},
"dependencies": {
"bootstrap": "^4.0.0",
"bootstrap-social": "^5.1.1",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"popper.js": "^1.12.9"
}
}
ERROR
PS I:\Projects\Bootstrtao-test> npm run build
> confusion#1.0.0 build I:\Projects\Bootstrtao-test
> npm run clean && npm run imagemin && npm run copyfonts && npm run usemin
> confusion#1.0.0 clean I:\Projects\Bootstrtao-test
> rimraf dist
> confusion#1.0.0 imagemin I:\Projects\Bootstrtao-test
> imagemin img/* --out-dir=dist/img
4 images minified
> confusion#1.0.0 copyfonts I:\Projects\Bootstrtao-test
> copyfiles -f node_modules/font-awesome/fonts/* dist/fonts
> confusion#1.0.0 usemin I:\Projects\Bootstrtao-test
> usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html
I:\Projects\Bootstrtao-test\node_modules\usemin\lib\processBlocks.js:39
throw Error('Unsupport format: ' + block.type);
^
Error: Unsupport format: CSS
at I:\Projects\Bootstrtao-test\node_modules\usemin\lib\processBlocks.js:39:10
at Array.forEach (<anonymous>)
at module.exports (I:\Projects\Bootstrtao-test\node_modules\usemin\lib\processBlocks.js:9:9)
at usemin (I:\Projects\Bootstrtao-test\node_modules\usemin\usemin.js:27:42)
at Object.<anonymous> (I:\Projects\Bootstrtao-test\node_modules\usemin-cli\index.js:52:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 usemin: `usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 usemin 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! C:\Users\PetrosBelachew\AppData\Roaming\npm-cache\_logs\2020-11-20T12_05_10_237Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 build: `npm run clean && npm run imagemin && npm run copyfonts && npm run usemin`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 build 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! C:\Users\PetrosBelachew\AppData\Roaming\npm-cache\_logs\2020-11-20T12_05_10_452Z-debug.log
Any ideas on how to fix this?
I have fixed the issue by myself,after observing the error above(Error: Unsupport format: CSS).Then checked my index.html file,that the code like this
<!--build:CSS CSS/main.css-->
.....
<!--endbuild-->
on this line above,you can see that CSS has to be lower case css.After that I have solved other issues within my HTML file.Then the build was successful.

npm run prefix:css ERR

My System confg
OS : Microsoft Windows 10,
code editor : Visual Studio Code
node version : v10.13.0,
npm version : 6.4.1
following commands
npm run start, npm run compile:sass, npm run concat::css are working well.
But npm run prefix:css is throwing error.
I work under two circumstances, the one is able to connect the internet and the other is not.
Yesterday I work it at home which is able to connect the internet.
At first, I did npm install postcss --save-dev.
Then I did npm run prefix:css.
The console threw ERROR.
What's my problem ?
How can I fix the problem.
Strangely, 'postcss.cmd' command isn't made in the 'node_modules.bin' folder.
Other normal commands are made in the the 'node_modules.bin' folder.
my package.json is
{
"name": "natours",
"version": "1.0.0",
"description": "landing page for natours",
"main": "index.js",
"scripts": {
"watch:sass": "node-sass sass/main.scss css/natours.sass -w",
"devserver": "live-server",
"start": "npm-run-all --parallel devserver watch:sass",
"compile:sass": "node-sass sass/main.scss css/natours.comp.css",
"concat:css": "concat -o css/natours.concat.css css/icon-font.css css/natours.comp.css",
"prefix:css": "postcss --use autoprefixer -b 'last 10 versions' css/natours.concat.css -o css/natours.prefix.css",
"compass:css": "node-sass css/natours.prefix.css css/natours.css --output-style compressd",
"build:css": "npm-run-all compile:sass concat:css prefix:css compass:css"
},
"author": "Jsmile",
"license": "ISC",
"dependencies": {
"save-dev": "^2.0.0"
},
"devDependencies": {
"autoprefixer": "^9.4.4",
"concat": "^1.0.3",
"node-sass": "^4.11.0",
"npm-run-all": "^4.1.5",
"postcss": "^7.0.8"
}
}
Here I reproduced the error by following commands
F:\개인\workspace\CSS\css_sass\1-Natours>npm install postcss --save-dev
npm WARN natours#1.0.0 No repository field.
+ postcss#7.0.8
updated 1 package and audited 639 packages in 2.778s
found 0 vulnerabilities
F:\개인\workspace\CSS\css_sass\1-Natours>npm run prefix:css
> natours#1.0.0 prefix:css F:\개인\workspace\CSS\css_sass\1-Natours
> postcss --use autoprefixer -b 'last 10 versions' css/natours.concat.css -o css/natours.prefix.css
'postcss'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는 배치 파일이 아닙니다.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! natours#1.0.0 prefix:css: `postcss --use autoprefixer -b 'last 10 versions' css/natours.concat.css -o css/natours.prefix.css`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the natours#1.0.0 prefix:css 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! C:\Users\No.1\AppData\Roaming\npm-cache\_logs\2019-01-10T22_37_17_074Z-debug.log
"prefix:css": "postcss --use autoprefixer -b \"last 10 versions\" css/natours.concat.css -o css/natours.prefix.css"
In Windows OS the below syntax is used:
"prefix:css": "postcss --use autoprefixer -b \"last 10 versions\" css/natours.concat.css -o css/natours.prefix.css"
The problem is probably with postcss, try using postcss-cli instead.
But surely, running
postcss --use autoprefixer -b 'last 10 versions' css/natours.concat.css -o css/natours.prefix.css
directly in your terminal will work, don't run the script.
Install both:
npm install postcss --save-dev
npm install postcss-cli --save-dev
then:
npm run prefix:css

Resources