npm ERR! Invalid Version: - javascript

Please I got the below error while setting up an angular project
npm WARN config global --global, --local are deprecated. Use --loca tion=global instead.
npm ERR! Invalid Version:
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Local\npm-cache_logs\2022-08-02T17_5
8_35_503Z-debug-0.log
The version in the package.json is
{
"name": "angular-front-end",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},

Related

How to use Nodejs build in production mode using babel for my DockerImage

i Have a nodejs application and its working fine but in my structure i dont have a src folder i just have all other files and am using MVC but am having the error
here is my script
"scripts": {
"start": "babel-node server.js",
"dev": "nodemon --exec npm start",
"build-babel": "babel -d ./build ./server.js -s",
"build": "babel ./Myfolder --out-dir dist --copy-files",
"serve": "node dist/index.js",
"sequelize": "sequelize"

How do I set webpack mode

I'm trying to configure my script (in package.json) in such a way that I can run webpack in production or development mode via cli.
package.json
"scripts": {
"start": "webpack serve",
"build": "webpack --mode=production"
in my webpack.config.js file, I was expecting process.env.NODE_ENV to equal to whatever I set the mode to be. Instead, I keep getting undefined please how can I make it work
For the Dev Server
First, install webpack-dev-server with following command:
npm install webpack-dev-server
Add following line to the package.json script:
"scripts": {
"start": "webpack-dev-server --mode development"
}
For Production build
Add the following line to the scripts section of package.json:
"build": "node_modules/.bin/webpack --mode production"
The scripts section in package.json with both the dev and production build will look like this:
"scripts": {
"build": "node_modules/.bin/webpack --mode production",
"start": "webpack-dev-server --mode development"
}

How to add TS files to launch vue3 application in prod

Current folder structure:
/appname/server.js
/appname/package.json
Current package.json
"scripts":
{
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"start": "node server.js",
},
I'd like to write serve.js using TS. I know how to do in a typical TS project, but i'm not able to do so when webpacks are involved. If I update tsconfig to include serve.ts the js file doesn't end up in the dist folder.
Wanted folder structure:
/appname/server.ts
/appname/package.json
Wanted package.json
"scripts":
{
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"start": "node dist/server.js",
},
To make this even more complicated, the dist folder is needed to drive the application, so I rather not mess with it, putting server.js in a different folder is probably a better approach.
You could use ts-node to run server.ts directly:
Install ts-node as a devDependency:
npm i -D ts-node
Update your NPM script to use ts-node instead of node:
{
"scripts": {
"start": "ts-node server.ts"
}
}
Or you can avoid a devDependency with npx ts-node:
{
"scripts": {
"start": "npx ts-node server.ts"
}
}

NextJs 5.0.0 Heroku Internal Server Error

These are my scripts:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js",
"heroku-postbuild": "next build"
},
This is my procfile:
web: npm start -- --port $PORT
These are my config variables:
NPM_CONFIG_PRODUCTION=false
You have to update next to 5.0.1-canary.4 this was actually a nextjs bug.

Unable to run babel command on CLI

I am trying to install flow as docs suggests https://flow.org/en/docs/install/ It requires to install babel-cli to run babel.
I installed babel-cli using below command https://babeljs.io/docs/usage/cli/
npm install --save-dev babel-cli
> npm install --save-dev babel-cli
todo-app#0.1.0 D:\React JS\todo-app
`-- babel-cli#6.24.1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.0.17 (node_modules\react-scripts\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.0.17: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN enoent ENOENT: no such file or directory, open 'D:\React JS\todo-app\node_modules\acorn-dynamic-import\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'D:\React JS\todo-app\node_modules\create-hmac\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'D:\React JS\todo-app\node_modules\create-hash\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'D:\React JS\todo-app\node_modules\diffie-hellman\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'D:\React JS\todo-app\node_modules\pbkdf2\package.json'
package.json
{
"name": "todo-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-redux": "^5.0.5",
"react-tap-event-plugin": "^2.0.1",
"redux": "^3.6.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"react-scripts": "1.0.7",
"redux-devtools": "^3.4.0",
"webpack": "^2.6.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
When I run babel command then it gives me an error 'babel' is not recognized as an internal or external command, operable program or batch file.
Update
It is because "local binaries probably aren't found because the local ./node_modules/.bin is not in $PATH" - but do you think Is it good to add node_modules/.bin of all projects in a $PATH ? or Is there any alternative to do ?
PS: I am on windows machine.
Add a babel script in your package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"babel": "babel"
}
Then you can run babel with:
npm run babel
If you want to pass arguments when running from the command line, separate them from the command with -- (more info). For example:
npm run babel -- --help
This way you run the version of babel specified in package.json and installed by npm and you do not need to edit your PATH variable.
Note: This is the same approach as flow recommends for itself in its installation instructions,. (Switch it to npm at the top then scroll down to "Setup Flow")

Categories