Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to execute a script from package.json on Windows throws a JScript error

So I'm trying to build the javascriptair/site. Inside the package.jsonThere is an npm script that points at a javascript "command" package-scripts. That repository is found https://github.com/kentcdodds/p-s. In Windows it errors out with a JScript error.

Script: C:[path_to_code]\package-scripts.js
Line: 2
Char: 1
Error: Syntax error
Code: 800A03EA
Source: Microsoft JScript compilation error

So in the package.json, what it has is this

"scripts": {
    "start": "package-scripts"
}

If I change the package.json to the following:

"scripts": {
    "start": "package-scripts.cmd"
}

I can get the server to start. So my question is, why is this happening, and how can we change the package.json to make it cross platform with the same command.

like image 855
comfroels Avatar asked Sep 06 '25 03:09

comfroels


2 Answers

The reason and a workaround are pointed here: https://github.com/javascriptair/site/issues/98#issuecomment-404420108

So the problem is there is a js file in the root of repo with the same base name as binary. And npm on windows first tries to run it as binary instead of looking into './node_modules/.bin' So to workaround an issue just remove .JS from PATHEXT environment variable and restart

I've got the same problem: when there is tslint.js file in the root dir of the package and an npm script in package.json just calls tslint, jscript is fired by npm instead of node, resulting in "Microsoft JScript compilation error" popup. Removing .js from PATHEXT helps.

like image 190
Konstantin Pelepelin Avatar answered Sep 07 '25 21:09

Konstantin Pelepelin


This is a Node.js module that is meant to be required by another script. It is not designed to be executed by Microsoft JScript and if you try running the script file by itself in Node it will not do anything. This is because all of the internal methods of this particular script are supposed to be externally exposed before use.

Upon further examination it seems that the actual file you are probably looking for is in the bin folder. Run that with the node command and see what happens.

like image 21
Jonathan Gray Avatar answered Sep 07 '25 19:09

Jonathan Gray