800A03EA javascript 语法 JScript 编译错误

800A03EA javascript syntax JScript compilaton error

关于 JScript 和节点,我的计算机出现了一个非常烦人的编译问题,我已经尝试了互联网提供的几个说明,但问题似乎仍然存在。

光盘>项目
npm init还行
npm install -g 并且本地正常
npm start > 启动问题:脚本 > app.jsnode app.js 正常

如果它 运行s 我收到 Windows 主机服务器错误 #800A03EA syntax/compilation 问题。

但是,如果我 运行 代码 npx http-server,我可以毫无问题地完成我的 PWA 项目。

我已经尝试了几个 'fix' 工具,修复,注册表验证,但其中 none 似乎可以解决问题。

JScript(由 windows 脚本宿主解释,WSH)与 JavaScript(由 node* 解释)不同。

提到的错误听起来好像 Windows 脚本宿主的 JScript 解释器试图执行 JavaScript 用于节点的文件。

确保您 运行 您的代码使用节点 (node app.js) 而不是 WSH。 windows 中 *.JS 的默认文件关联是 WSH,因此双击或仅 运行ning app.js 将 运行 WSH。

还要确保 package.json 中的 start 命令实际上设置为 node app.js,我感觉它只设置为 app.js.

... 
"scripts": {
  "start": "node app.js"
} 
... 

那么,npm start 应该可以。

*:当然 node 不是 Javascript 的唯一解释器,但它是这里相关的解释器。

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.5
3 info using node@v12.16.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle np@1.0.0~prestart: np@1.0.0
6 info lifecycle np@1.0.0~start: np@1.0.0
7 verbose lifecycle np@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle np@1.0.0~start: PATH: C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Dev\Desktop\Fetch api\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python38\Scripts\;C:\Python38\;C:\Program Files (x86)\Intel\TXE Components\iCLS\;C:\Program Files\Intel\TXE Components\iCLS\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\TXE Components\DAL\;C:\Program Files (x86)\Intel\TXE Components\DAL\;C:\Program Files\Intel\TXE Components\IPT\;C:\Program Files (x86)\Intel\TXE Components\IPT\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;C:\Users\Dev\AppData\Local\Microsoft\WindowsApps;;C:\Users\Dev\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Dev\AppData\Roaming\npm
9 verbose lifecycle np@1.0.0~start: CWD: C:\Users\Dev\Desktop\Fetch api
10 silly lifecycle np@1.0.0~start: Args: [ '/d /s /c', 'node scripts.js' ]
11 silly lifecycle np@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle np@1.0.0~start: Failed to exec start script
13 verbose stack Error: np@1.0.0 start: `node scripts.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:310:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:310:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid np@1.0.0
15 verbose cwd C:\Users\Dev\Desktop\Fetch api
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "start"
18 verbose node v12.16.3
19 verbose npm  v6.14.5
20 error code ELIFECYCLE
21 error errno 1
22 error np@1.0.0 start: `node scripts.js`
22 error Exit status 1
23 error Failed at the np@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 ]

PS C:\Users\Dev\Desktop\Fetch api> npm start

> np@1.0.0 start C:\Users\Dev\Desktop\Fetch api
> node scripts.js

C:\Users\Dev\Desktop\Fetch api\scripts.js:1
var button = document.querySelector('.button')
             ^

ReferenceError: document is not defined
    at Object.<anonymous> (C:\Users\Dev\Desktop\Fetch api\scripts.js:1:14)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! np@1.0.0 start: `node scripts.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the np@1.0.0 start 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\Dev\AppData\Roaming\npm-cache\_logs20-05-23T18_39_34_693Z-debug.log

PACKAGE JSON

{
  "name": "np",
  "version": "1.0.0",
  "main": "script.js",
  "scripts": {
    "start": "node scripts.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "npm": "^6.14.5",
    "prpl-server": "^1.4.0"
  },
  "devDependencies": {},
  "repository": {
    "type": "git",
    "url": "https://github.com/mendesbayout/Fetch-api-simple-forecast.git"
  },
  "bugs": {
    "url": "https://github.com/mendesbayout/Fetch-api-simple-forecast/issues"
  },
  "homepage": "https://github.com/mendesbayout/Fetch-api-simple-forecast#readme",
  "description": ""
}

在js文件开头添加这一行:

#!/usr/bin/env node

它会告诉你的系统使用哪个解释器运行文件