Volta with yarn run build system cannot find the path specified - node.js

This is the first time I'm using Volta, so bear with me.
I have installed globally typescript, node and yarn
yarn -v >> 1.22.10
node -v >> v14.15.4
npm -v >> 6.14.10
These commands work inside and outside my project folder, with the same results.
However if I use yarn build from inside vscode the output is an error stating:
System cannot find the path specified
If I do the same from outside vscode I get the same result:
If I go to the node_modules/.bin folder inside vscode, the command still doesn't work (this time I just only run tsc). The error is the following:
The term tsc is not a cmdlet recognized command, function, script file or executable program. Verify if the name is written correctly or, if there is an access route, verify the route is correct and try again.
But if the command is executed from outside vscode in a cmd window, it works as expected, because tsc is really there:
Additionally, if I run npm run build inside vscode, the command works as expected. This is my package.json:
{
"name": "socket-server",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "yarn build --watch --preserveWatchOutput",
"lint": "eslint src --ext js,ts",
"test": "jest"
},
"devDependencies": {
"eslint": "^7.19.0",
"jest": "^26.6.3",
"typescript": "^4.1.3"
},
"volta": {
"node": "14.15.4",
"yarn": "1.22.10"
}
}
I do suspect of volta because volta is managing yarn version, but no npm; but I don't really know what's the issue.
I'm using Windows and my PATH has the following entries:
What am I doing wrong?
Edit: Yes, Shell command shortcut exists:

the problem is about vsCode, you should run code . in cmd because if you Open the Command Palette (Ctrl + Shift + P) and type
Shell Command: Install 'code' command in PATH
you won't see noting, after running code . in cmd when you should see like this photo, every things will be fine

I’m not sure for Windows, but usually the scripts in node_modules/.bin are symbolic links to scripts. For instance, node_modules/.bin/tsc might point to node_modules/typescript/bin/tsc.
It works outside of the directory because then it uses the global version of tsc.
Seeing your error, I’m suspecting that the symlinks are broken. Maybe just try to remove node_modules directory and redo an npm install.
PS: I’m not familiar with Volta, but it looks more like an NPM problem.

Related

create-react-app + npm start - 'react-scripts' is not recognized as an internal or external command

Similar questions that I have tried following
"npm-run-all" is not recognized as an internal or external command
"'react-scripts' is not recognized as an internal or external command"
I am trying to create a React project via the create-react-app cli, but after creating the project I get the error
'react-scripts' is not recognized as an internal or external command, operable program or batch file"
when I try to launch the dev server via npm start.
What I have tried:
1) Make sure Node and npm are installed and up to date. From the project directory I run (via powershell)
> npm -v
6.7.0
> node -v
v11.11.0
2) Ensure that 'react-scripts' is listed with the correct version number in package.json
"name": "clipd2",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "^2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}...
3) Delete node_modules folder and package-lock.json and reinstall npm packages
rm -r -fo node_modules
rm package-lock.json
npm install
npm install -S react-scripts
After instalation the react-scripts directory is found (and populated) in node_modules
4) Make sure npm is in the environment PATH variable
> echo $Env:Path
....C:\Users\notMyUsername\AppData\Roaming\npm
I am at a loss for next steps. Strangely enough, I have another React app housed in the same parent directory
clipdReact
clipd
clipd2
And there are no problems when using npm start in the clipd project (whereas the failing project is clipd2)
Any suggestions or tips would be greatly appreciated!
**UPDATE
This bug was filed but is still open
react-scripts is not recognized
You can start the dev server (from your project's directory) with
.\node_modules\.bin\react-scripts start
Be careful generating the production build with a command similar to the one above - I had problems with babel and polyfills when trying to do so.
What worked for me in the end, was setting the script shell to powershell. The command for that is npm config set script-shell powershell and npm config delete script-shell to reset the config. I'm not sure why that worked, my guess is that since there are always 3 script files in node_modules\.bin that somehow the wrong shell was used for the wrong script or something like that.
npm install react-scripts --save --force

Nothing happens when entering the babel command

I just installed babel as followed: npm install -g babel-cli
However when I try to enter the babel command in either nodejs cmd (as admin) or my editor pycharm's terminal, nothing happens.. It's like it's loading or something but even waiting for more than 20min. nothing appeares.
Screenshot
This started happening after I added C:\Users\sebas\PycharmProjects\storage\node_modules\.bin as a path to the environment variables
Before that, every time I tried running babel I would get a babel command not recognized as an external or internal command error.
What is going on?
In my opinion, the easiest way to solve this (see: not adding to your path) is to simply add an entry inside your package.json
For example:
...
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib --copy-files",
},
...
This way, all you need to do is run npm run build, and it will take care of figuring out where babel is. Also, remember to add a .babelrc with the following content if you're using babel-preset-env:
{
"presets": ["env"]
}
More than likely because you have not added the .\node_modules\.bin directory to your path.
Until you do that, you can use .\node_modules\.bin\babel

my npm-lint is throwing error "missing script: lint"

I am trying to run npm run locally, and ran npm init, that created package.json. Here is my package.json
"name": "ironic-ui",
"version": "1.0.0",
"description": "======================== Team and repository tags ========================",
"main": "test-shim.js",
"directories": {
"doc": "doc"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.openstack.org/openstack/ironic-ui"
},
"author": "",
"license": "ISC"
}
Is there missing something? Or do i need to install something more? I am getting an error "Missing script: lint"
Thanks
You need to setup linter and add lint command in your package.json
Many linter are available. Assuming you setup eslint
https://www.npmjs.com/package/eslint
it would look something like this
// package.json
{
//...
"scripts": {
"lint": "eslint.js"
}
}
Add this script to your package.json file:
"lint": "./node_modules/.bin/eslint ."
Should not be removing eslint, instead should try to configure it to make it work to your preferences.
However, if you need to remove it because of time or other constraint
From firebase.json delete "npm --prefix \"$RESOURCE_DIR\" run lint"
From Package.json delete "lint": "eslint .", (should be within the scripts:)
Also from Package.json delete these devDependencies
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0"`
Delete this file from repo `.eslintrc.js
Then run npm i
then you should be able to run firebase deploy
I got the same problem.
I deleted functions folder, .firebaserc and firebase.json.
Then reinstalled firebase-tools
npm install -g firebase-tools
After firebase init, chose functions, it asked
Do you want to use ESLint to catch probable .....?.
I typed No.
It worked fine for me.
If you want to remove eslint from your Firebase Functions project, you can go to firebase.json and delete the line npm --prefix \"$RESOURCE_DIR\" run lint (inside predeploy). After this, you can delete the .eslintrc.json file inside your functions project
I ran into this issue when after setting up a firebase functions project inside a project that already had a firebase function elsewhere. It seems that firebase init doesn't necessarily know which project to set as "source" in firebase.json.
In my case, firebase.json simply pointed to the wrong source dir. I corrected it to point the my intended directory - issue solves.
Note: In my case, linting was desired, so removing linting was not the solution.
I get the exact same problem when I do:
firebase deploy --only functions
(-- only functions is optional), it redirects me to
npm --prefix %RESOURCE_DIR% run lint
It worked fine for me when I removed lint, thus having:
npm --prefix %RESOURCE_DIR% run
only.
For me i was just running the command without entering the function folder so it was not finding it i was just running this function on the project folder. So run cd function in your cmd if your are just in the project folder then run the command again but if the script is not in your package.json as mentioned above or you said no to eslint/lint when you initialized your firebase project lint wont work but others command that exist in your scripts work.
Editing package.json from "lint": "eslint .", to "lint": "eslint", worked for me.

How do I deploy my Typescript Node.js app to Heroku?

When testing locally I was previously running:
"build-live": "nodemon --exec ./node_modules/.bin/ts-node -r dotenv/config -- ./index.ts"
I then figured my Procfile should be something like:
web: ./node_modules/.bin/ts-node -- ./index.ts
But it says module 'typescript' not found, even when it is in package.json. I read in a few places that ts-node is not the way to go to deploy to Heroku, so I am not sure what to do.
UPDATE: I think I am supposed to compile it, so I tried:
web: ./node_modules/.bin/tsc --module commonjs --allowJs --outDir build/ --sourceMap --target es6 index.ts && node build/index.js
This succeeds, however when actually running it, a bunch of the libs I'm using get "Cannot find module '...'".
Alternatively you can have the TypeScript compile as a postinstall hook and run node build/index.js as the only Procfile command:
Your package.json should contain a postinstall hint that gets executed after npm install and before the node process launches:
"scripts": {
"start": "node build/index.js",
"build": "tsc",
"postinstall": "npm run build"
}
You can then leave your Procfile as is:
web: npm start
This 'build on deploy' approach is documented by Heroku here.
The command you've given Heroku is to launch the web "process" by compiling index.ts and dependencies and starting node at index.js. Depending on how things are timed, index.js might or might not exist at the time node starts.
You need to already have your sources compiled by the time you want to start your app. For example, web should just be web: node index.js or similar.
Each build process is different, so you need to figure that out for your own setup. But, suppose you have a classical setup where you push to git and then Heroku picks up that change and updates the app with the new slug. You could just compile things locally and include index.js and any other build output in the repository, for it to be available in the slug for Heroku to use.
A better approach is to use a build server which has an integration with Heroku. After you do the build there, configure it to send the build results to Heroku. Travis has a straighforward setup like this. This way you don't need to include build outputs in your repository, which is considered an anti-pattern.
On a sidenode, try using a tsconfig.json to keep the tsc configuration. It will save you from having to write such long command lines all over the place.
Fabian said that we could do something like:
"scripts": {
"start": "node build/index.js",
"build": "tsc",
"postinstall": "npm run build"
}
As of me writing this, I tested this and can state: postinstall is not required since build script is ran by Heroku. If you want to do it without build script, then you can use heroku-postbuild which will run after dependencies are installed there you run tsc to compile.
My problem was about missing Typescript npm modules. The Typescript compiler tsc was not found when deployed the app to Heroku.
The Heroku deploy process (rightly) does not install development dependencies, in my case the Typescript module was part of devDependencies and thus the tsc command was not running on the Heroku platform.
Solution 1
Add typescript to dependencies: npm i typescript -s
Solution 2
Open Heroku console:
Select console type:
Run the command npm i typescript && npm run tsc
Install typescript as a dev dependency (cf. https://www.typescriptlang.org/download). Once built, your app does not need typescript anymore!
npm install -D typescript
Then in your package.json:
{
"main": "index.js", // <- file will be generated at build time with `tsc`
"scripts": {
"build": "tsc",
"start": "node ."
"start:dev": "ts-node index.ts" // idem, install ts-node as a dev dependency
}
}
The key point here is "build": "tsc".
Why?
Heroku does install all dependencies during build and remove the dev dependencies before the app is deployed (source here).
Node.js deployments will automatically execute an app’s build script during build (since March 11. 2019 source here)
In package.json
"scripts": {
"tsc": "./node_modules/typescript/bin/tsc",
"postinstall": "npm run tsc"
},
Works for me for Heroku deployment.
Installing typescript npm install -D typescript and writing tsc in the build script "build": "tsc", does not work for me. Also, try to run npm i typescript && npm run tsc in the Heroku console which also does not work.
In my case, I remove some dependencies from "devDependencies" to "dependencies", so it goes like this:
"dependencies": {
// The other dependencies goes here, I don't touch them.
// But all TS dependencies I remove to here.
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.3",
"ts-loader": "^8.0.18"
},

NODE_PATH not recognized

Here is my package.json script:
"scripts": {
"start": "NODE_PATH=$NODE_PATH:./shared node",
"dev": "npm run start & webpack-dev-server --progress --color"
},
When I run npm start in Windows 8 it shows the below error:
node_path is not recognized as a internal or external command, operable program or batch file
I had the same problem when I wanted to set the environment variable in a browserify script:
"scripts": {
"build:symlinked": "NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}
To be able to use linked node modules that are requiring peer-dependencies.
As mentioned above, you can try to set the environment variable manually or by script where it seems you have to use different commands depending on what command line tool you use.
For not having to do this every time, I found that npm package: cross-env.
By installing it and applying the script like this
"scripts": {
"build:symlinked": "cross-env NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}
I was able to solve that problem. This is mainly useful, if you work in a team with mixed MAC/Linux and Windows users, so you don't have to to take care about applying the Environment variables in such scripts anymore.
You don't need to define environment variable in package.json just use this
{
"scripts" : "node server.js"
}
or define what you want, here is the reference link.

Resources