I'm trying to transpile an ES6 file using Babel - but NPM doesn't like the command babel src --out-dir output which is run using a script in my package.json.
However, when I install Babel globally and run the same command without using the script, it works just fine.
I would like to avoid installing Babel globally if I don't have to.
Error (see debug log below)
TypeError: src/person.js: Expected 'input' to be a 'string', got 'number'
And looks like the command babel src --out-dir output "fails on your system"
Project setup
-> root
-> node_modules
-> output
-> src
- person.js
- .babelrc
- package.json
package.json
{
"name": "Test",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "babel src --out-dir output"
},
"author": "Me",
"license": "UNLICENSED",
"devDependencies": {
"babel-cli": "~6.11.4",
"babel-preset-es2015": "^6.9.0"
}
}
person.js
class Person {
constructor(name) {
this.name = name;
}
}
.babelrc
{
"presets": ["es2015"]
}
Debug log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files (x86)\\node.exe',
1 verbose cli 'C:\\Program Files (x86)\\node_modules\\npm\\bin\\npmcli.js',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm#2.15.8
3 info using node#v4.4.7
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info prebuild Codemode#0.0.0
6 info build Test#0.0.0
7 verbose unsafe-perm in lifecycle true
8 info Test#0.0.0 Failed to exec build script
9 verbose stack Error: Test#0.0.0 build: `babel src --out-dir output`
9 verbose stack Exit status 1
9 verbose stack at EventEmitter.<anonymous> (C:\Program Files (x86)\node_modules\npm\lib\utils\lifecycle.js:217:16)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at EventEmitter.emit (events.js:172:7)
9 verbose stack at ChildProcess.<anonymous> (C:\Program Files (x86)\node_modules\npm\lib\utils\spawn.js:24:14)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at ChildProcess.emit (events.js:172:7)
9 verbose stack at maybeClose (internal/child_process.js:827:16)
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid Codemode#0.0.0
11 verbose cwd C:\Users\me\Dev\Test
12 error Windows_NT 6.1.7601
13 error argv "C:\\Program Files (x86)\\node.exe" "C:\\Program Files (x86)\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
14 error node v4.4.7
15 error npm v2.15.8
16 error code ELIFECYCLE
17 error Test#0.0.0 build: `babel src --out-dir output`
17 error Exit status 1
18 error Failed at the Test#0.0.0 build script 'babel src --out-dir output'.
18 error This is most likely a problem with the Test package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error babel src --out-dir output
18 error You can get information on how to open an issue for this project with:
18 error npm bugs Test
18 error Or if that isn't available, you can get their info via:
18 error
18 error npm owner ls Test
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]
I'm really not sure where this is going wrong, and can't find any posts on the error.
Thanks for your help
Problem solved (by fluke)!
I'm still unsure what the issue was, however I have since added webpack to my project, and added a further script to run the webpack command. This worked fine, so I tried the npm run build command again and it worked (I checked and babel-cli -g was uninstalled too).
If anyone can shed any light on what went wrong, that would be great!!!
Thanks
Related
I'm currently following a tutorial, and I've made sure to follow each and every step. I'm trying to locally host my javascript app at localhost:3000. However, I'm unable to do so, and whenever I try to run npm run dev I get the following error log:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using npm#6.14.4
3 info using node#v10.19.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle personalwebsite#0.0.0~predev: personalwebsite#0.0.0
6 info lifecycle personalwebsite#0.0.0~dev: personalwebsite#0.0.0
7 verbose lifecycle personalwebsite#0.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle personalwebsite#0.0.0~dev: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/omar-backup/Desktop/MrBoogle.github.io/personalWebsite/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 verbose lifecycle personalwebsite#0.0.0~dev: CWD: /home/omar-backup/Desktop/MrBoogle.github.io/personalWebsite
10 silly lifecycle personalwebsite#0.0.0~dev: Args: [ '-c', 'vite' ]
11 silly lifecycle personalwebsite#0.0.0~dev: Returned: code: 1 signal: null
12 info lifecycle personalwebsite#0.0.0~dev: Failed to exec dev script
13 verbose stack Error: personalwebsite#0.0.0 dev: `vite`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid personalwebsite#0.0.0
15 verbose cwd /home/omar-backup/Desktop/MrBoogle.github.io/personalWebsite
16 verbose Linux 5.4.0-26-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
18 verbose node v10.19.0
19 verbose npm v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error personalwebsite#0.0.0 dev: `vite`
22 error Exit status 1
23 error Failed at the personalwebsite#0.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
I've spent about an hour now trying to figure this out but have yet to find anything. I installed vite but nothing gets hosted (I'm trying to host my app on localhost:3000) and instead a weird window pops up using qt5ct. Unfortunately that no longer works because I probably messed something up while trying to get this to work.
The tutorial I'm following can be found here. I'm running into issues around the 2:45 mark.
When you create a project with npm init, like on the tutorial you've seen, a project from a template with be created at some directory. On your case, you ran:
npm init #vitejs/app
This command got you a folder with some predefined template of Node.JS, which created a package.json for you, wich have all the dependencies required for that project to being able to work. At your case, for example:
{
"name": "vite-project",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"vite": "^2.3.3"
}
}
As you can see, there is a devDependency call vite, which need to be installed to execute the npm script of dev, which translates to "dev": "vite".
When you ran before, the vite dependencie wasnt installed on the project, and that was the reason of the error:
error personalwebsite#0.0.0 dev: `vite`
When you run npm install, it installed all the required dependencies of package.json. So after you installed the vite dependency with npm install (which will take the package.json definition), it stopped lacking dependencies.
That is why your error change to:
Cannot find module 'worker_threads'
This is other error, and is probably because you are using and old version of node (info using node#v10.19.0).
Trying to replicate I encounter the same problem:
But when I update to a newer version (Node 14), it didn't happend. So, just update your node version
i am learning node.js. I initialized a package.json file in my project and I used a special lifecycle script "start" in my JSON file. Before initializing npm I ran "node app.js" command in terminal to run the code inside app.js. But when I ran the code using NPM, I am getting an error after running this command:
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/apple/.npm/_logs/2021-02-01T15_18_14_323Z-debug.log
here are the contents of the log file:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/Users/apple/.nvm/versions/node/v14.7.0/bin/node',
1 verbose cli '/Users/apple/.nvm/versions/node/v14.7.0/bin/npm',
1 verbose cli 'start'
1 verbose cli ]
2 info using npm#6.14.7
3 info using node#v14.7.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle guide#1.0.0~prestart: guide#1.0.0
6 info lifecycle guide#1.0.0~start: guide#1.0.0
7 verbose lifecycle guide#1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle guide#1.0.0~start: PATH: /Users/apple/.nvm/versions/node/v14.7.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/apple/Desktop/guide/node_modules/.bin:/Users/apple/.nvm/versions/node/v14.7.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands
9 verbose lifecycle guide#1.0.0~start: CWD: /Users/apple/Desktop/guide
10 silly lifecycle guide#1.0.0~start: Args: [ '-c', 'node app.js' ]
11 silly lifecycle guide#1.0.0~start: Returned: code: 1 signal: null
12 info lifecycle guide#1.0.0~start: Failed to exec start script
13 verbose stack Error: guide#1.0.0 start: `node app.js`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/Users/apple/.nvm/versions/node/v14.7.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:314:20)
13 verbose stack at ChildProcess.<anonymous> (/Users/apple/.nvm/versions/node/v14.7.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:314:20)
13 verbose stack at maybeClose (internal/child_process.js:1051:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid guide#1.0.0
15 verbose cwd /Users/apple/Desktop/guide
16 verbose Darwin 17.7.0
17 verbose argv "/Users/apple/.nvm/versions/node/v14.7.0/bin/node" "/Users/apple/.nvm/versions/node/v14.7.0/bin/npm" "start"
18 verbose node v14.7.0
19 verbose npm v6.14.7
20 error code ELIFECYCLE
21 error errno 1
22 error guide#1.0.0 start: `node app.js`
22 error Exit status 1
23 error Failed at the guide#1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
You should write start like this : "start" : "node app.js". And you must install node_modules. For that you can write console npm i. Modules will install and it should not be a problem.
There are many things to do for creating a start script:
First things first, to initialize a node and npm project, there has to be a package.json file. It can be created manually, but it is advisable to use the command npm init in the terminal. This command walks you through creating a package.json file asking some questions. You can simply press enter, enter, if you want, but you could also answer them, no problem. You can also skip everything by running npm init -y instead of npm init.
Second, you have to create a script using the scripts object only, not anywhere else. To do that, open the file in your editor, look at where the object resides, or create a new object:
{
"name": "your-app",
"version": "0.0.1",
"main": "index.js",
"license": "ISC",
"scripts": {
"start": "node app.js" // here
}
}
Finally, run the script using the command npm run start in the terminal.
I'm very new to Node.js and Electron and wanted to run npm run build. Unfortunately, that only gives me out the error code ELIFECYCLE.
Here is my package.json:
{
"name": "firstelectronproject",
"version": "0.1.0",
"description": "My first Electron project",
"main": "main.js",
"scripts": {
"start": "electron index.js",
"package": "",
"build": "electron-packager . FEP"
},
"author": "F9lke <florian.thomasgoetzrath.de>",
"license": "MIT",
"dependencies": {
"electron": "^1.6.11"
},
"devDependencies": {
"asar": "^0.13.0",
"electron-packager": "^8.7.2"
}
}
Here is the log of my command prompt:
D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP>npm run build
> firstelectronproject#0.1.0 build D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP
> electron-packager . FEP
Packaging app for platform win32 x64 using electron v1.6.11
Command failed: npm prune --production
npm WARN invalid config loglevel="notice"
npm WARN firstelectronproject#0.1.0 No repository field.
npm ERR! May not delete: C:\Users\User\AppData\Local\Temp\electron-packager\win32-x64\FEP-win32-x64\resources\app\node_modules\.bin
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Roaming\npm-cache\_logs\2017-07-21T11_38_37_230Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! firstelectronproject#0.1.0 build: `electron-packager . FEP`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the firstelectronproject#0.1.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\User\AppData\Roaming\npm-cache\_logs\2017-07-21T11_38_37_293Z-debug.log
And here is the log output:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm#5.3.0
3 info using node#v6.11.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle firstelectronproject#0.1.0~prebuild: firstelectronproject#0.1.0
6 info lifecycle firstelectronproject#0.1.0~build: firstelectronproject#0.1.0
7 verbose lifecycle firstelectronproject#0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle firstelectronproject#0.1.0~build: PATH: C:\Users\User\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP\node_modules\.bin;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Brackets\command;C:\Program Files\nodejs\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Local\atom\bin;C:\Users\User\AppData\Roaming\npm
9 verbose lifecycle firstelectronproject#0.1.0~build: CWD: D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP
10 silly lifecycle firstelectronproject#0.1.0~build: Args: [ '/d /s /c', 'electron-packager . FEP' ]
11 silly lifecycle firstelectronproject#0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle firstelectronproject#0.1.0~build: Failed to exec build script
13 verbose stack Error: firstelectronproject#0.1.0 build: `electron-packager . FEP`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:289:16)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at EventEmitter.emit (events.js:191:7)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at ChildProcess.emit (events.js:191:7)
13 verbose stack at maybeClose (internal/child_process.js:891:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid firstelectronproject#0.1.0
15 verbose cwd D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP
16 verbose Windows_NT 10.0.15063
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v6.11.1
19 verbose npm v5.3.0
20 error code ELIFECYCLE
21 error errno 1
22 error firstelectronproject#0.1.0 build: `electron-packager . FEP`
22 error Exit status 1
23 error Failed at the firstelectronproject#0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
This seems to be related to a bug in electron-packager. As a workaround you could downgrade electron-packager to e.g. ^7.7.0. Also, you need to update the build command slightly, see below (Note, only showing the relevant parts):
{
"scripts": {
"build": "electron-packager ./ --platform=linux --arch=x64"
},
"dependencies": {
"electron": "^1.6.11"
},
"devDependencies": {
"electron-packager": "^7.7.0"
}
}
Note that you can use --all to build for all platforms.
Updating npm on server worked for me.
I solved this problem by installing the array unique and it started working:
npm install --save array-unique
I encountered a similar problem with electron-packager. Just added ./ --all to the end of the pack directive. Final result given below:
"pack": "electron-packager ./ --all"
I have tried the angular2 5 Min quickstart from https://angular.io/guide/quickstart. All files were created by copy & paste because i am lazy and because of possible faults. I preferred the TypeScript version. At the end, i must compile and start with "npm start". I do this as admin. my OS is Windows 10.
After start, I get some errors. this is the npm-debug.log:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm#2.9.1
3 info using node#v0.12.3
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose run-script [ 'prestart', 'start', 'poststart' ]
6 info prestart angular2-quickstart#1.0.0
7 info start angular2-quickstart#1.0.0
8 verbose unsafe-perm in lifecycle true
9 info angular2-quickstart#1.0.0 Failed to exec start script
10 verbose stack Error: angular2-quickstart#1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
10 verbose stack Exit status 2
10 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:213:16)
10 verbose stack at EventEmitter.emit (events.js:110:17)
10 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
10 verbose stack at ChildProcess.emit (events.js:110:17)
10 verbose stack at maybeClose (child_process.js:1015:16)
10 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
11 verbose pkgid angular2-quickstart#1.0.0
12 verbose cwd C:\web\angular2-quickstart
13 error Windows_NT 6.3.9600
14 error argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
15 error node v0.12.3
16 error npm v2.9.1
17 error code ELIFECYCLE
18 error angular2-quickstart#1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
18 error Exit status 2
19 error Failed at the angular2-quickstart#1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
19 error This is most likely a problem with the angular2-quickstart package,
19 error not with npm itself.
19 error Tell the author that this fails on your system:
19 error tsc && concurrently "npm run tsc:w" "npm run lite"
19 error You can get their info via:
19 error npm owner ls angular2-quickstart
19 error There is likely additional logging output above.
20 verbose exit [ 1, true ]
Can anybody help me get the quickstart app to start?
I also tried to start the index.html in Firefox ( because the .ts files are all translated in .js files ) but nothing happens.
Sorry, my fault. the file app.component.ts was empty. i filled it with the correct content and "run npm start" and it works. the lite browser starts, i see "My first Angular 2 App" and i will be happy until the end of my days.
I downloaded Angular phonecat example phoject, moved to this directory and tried 'npm start' command. Result:
0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli '/usr/local/Cellar/nvm/0.17.2/v0.10.32/bin/npm',
1 verbose cli 'start' ]
2 info using npm#2.1.4
3 info using node#v0.10.32
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart angular-phonecat#0.0.0
6 verbose unsafe-perm in lifecycle true
7 info angular-phonecat#0.0.0 Failed to exec prestart script
8 verbose stack Error: angular-phonecat#0.0.0 prestart: `npm install`
8 verbose stack Exit status 3
8 verbose stack at ChildProcess.<anonymous> (/usr/local/Cellar/nvm/0.17.2/v0.10.32/lib/node_modules/npm/lib/utils/lifecycle.js:212:16)
8 verbose stack at ChildProcess.emit (events.js:98:17)
8 verbose stack at maybeClose (child_process.js:756:16)
8 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:823:5)
9 verbose pkgid angular-phonecat#0.0.0
10 verbose cwd /Users/marya/JS:HTML:CSS/angular-phonecat
11 error Darwin 13.4.0
12 error argv "node" "/usr/local/Cellar/nvm/0.17.2/v0.10.32/bin/npm" "start"
13 error node v0.10.32
14 error npm v2.1.4
15 error code ELIFECYCLE
16 error angular-phonecat#0.0.0 prestart: `npm install`
16 error Exit status 3
17 error Failed at the angular-phonecat#0.0.0 prestart script.
17 error This is most likely a problem with the angular-phonecat package,
17 error not with npm itself.
17 error Tell the author that this fails on your system:
17 error npm install
17 error You can get their info via:
17 error npm owner ls angular-phonecat
17 error There is likely additional logging output above.
18 verbose exit [ 1, true ]
I don't understand why but I can't execute server. How can I fix it? Thanks in advance.
It seems node is installed with version node#v0.10.32
Anyhow, what really happens is that npm looks in your package.json file, and if you have something like
"scripts": { "start": "coffee server.coffee" } }
then it will do that. If npm can't find your start script, it will not work
try node start using
node <name of your node server>.js
and error seen in your angular-phonecat Try reinstalling it using npm command and try.