简体   繁体   English

NodeJS,包,nodemon

[英]NodeJS, Package, nodemon

Many attempts were made on running my JS file using nodemon and node.js but to no avail.许多尝试使用 nodemon 和 node.js 运行我的 JS 文件,但无济于事。 When running 'npm run testing.js' I get the following terminal messages...运行“npm run testing.js”时,我收到以下终端消息...

> CypherNetwork@1.0.0 testing C:\CypherNetwork
> nodemon testing

C:\CypherNetwork\node_modules\nodemon\bin\nodemon.js:15
  require('update-notifier')({ pkg }).notify();
                                   ^
SyntaxError: Unexpected token }
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "testing"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! CypherNetwork@1.0.0 testing: `nodemon testing`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the CypherNetwork@1.0.0 testing script 'nodemon testing'.
npm ERR! This is most likely a problem with the CypherNetwork package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nodemon testing
npm ERR! You can get their info via:
npm ERR!     npm owner ls CypherNetwork
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\CypherNetwork\npm-debug.log

this is most likely a package error but I see no errors in my json file.这很可能是一个包错误,但我在我的 json 文件中没有看到任何错误。

json file: json文件:

{
  "name": "CypherNetwork",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "testing": "nodemon testing"
  },
  "keywords": [],
  "author": "Mickell",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^2.0.2",
    "gulp": "^4.0.2"
  }

JS file I am trying to run with npm...我正在尝试使用 npm 运行 .js 文件...

const Cube = require('./block');

const cube = new Cube('somedata','test','lol','somedata');

console.log(cube.toString());

Error log...错误日志...

'C:\Program Files (x86)\nodejs\node.exe' --nolazy --debug-brk=51265 testing.js
Debugger listening on port 51265
c:\CypherNetwork\block.js:1
(function (exports, require, module, __filename, __dirname) { class Cube
                                                              ^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (c:\CypherNetwork\testing.js:1:76)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

Class contained in JS file made into a nodejs module...包含在 JS 文件中的类制作成 nodejs 模块...

class Cube
{
    constructor(timestamp,previousHash,hash,data)
    {
        this.timestamp = timestamp;
        this.previousHash = previousHash;
        this.hash = hash;
        this.data = data;
    }
//to debug our values for what is in our block chain
    toString()
    {
        return `Block -
        Timestamp:---${this.timestamp}
        previousHash:${this.previousHash.substring(0,10)}
        hash:--------${this.hash.substring(0,10)}
        data:--------${this.data}
        `;
    }
}

//exports our class as a module to access it in other files
module.exports = Cube;

Error message...错误信息...

'C:\Program Files (x86)\nodejs\node.exe' --nolazy --debug-brk=51281 block.js
Debugger listening on port 51281
c:\CypherNetwork\block.js:1
(function (exports, require, module, __filename, __dirname) { class Cube
                                                              ^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.runMain [as _onTimeout] (module.js:501:10)
    at Timer.listOnTimeout (timers.js:110:15)

Help is much appreciated, as I wish to learn from my errors as a node noobie.非常感谢帮助,因为我希望从我作为节点新手的错误中学习。 Thank you.谢谢你。

After about an hour of tampering, the issue was solved!经过大约一个小时的篡改,问题解决了! Update NPM and node version that accept ES6 interpolation when using java classes.更新在使用 java 类时接受 ES6 插值的 NPM 和节点版本。 (I hope this helped anybody who was using a node version for ES5.) (我希望这对使用 ES5 节点版本的人有所帮助。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM