簡體   English   中英

NodeJS,包,nodemon

[英]NodeJS, Package, nodemon

許多嘗試使用 nodemon 和 node.js 運行我的 JS 文件,但無濟於事。 運行“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

這很可能是一個包錯誤,但我在我的 json 文件中沒有看到任何錯誤。

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"
  }

我正在嘗試使用 npm 運行 .js 文件...

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

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

console.log(cube.toString());

錯誤日志...

'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)

包含在 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;

錯誤信息...

'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)

非常感謝幫助,因為我希望從我作為節點新手的錯誤中學習。 謝謝你。

經過大約一個小時的篡改,問題解決了! 更新在使用 java 類時接受 ES6 插值的 NPM 和節點版本。 (我希望這對使用 ES5 節點版本的人有所幫助。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM