2017-07-14 131 views
0

我剛剛導入我的Reactjs項目到新機器上的Ubuntu和安裝最依賴與npm install成功吧以下內容:NPM的NodeJS腳本失敗,出現「語法錯誤:意外的標記{」

npm WARN optional Skipping failed optional dependency /react-scripts/fsevents: 
npm WARN notsup Not compatible with your operating system or architecture: [email protected] 
npm WARN optional Skipping failed optional dependency /chokidar/fsevents: 
npm WARN notsup Not compatible with your operating system or architecture: [email protected] 

試圖運行

> [email protected] start /root/17-visit-booker-frontend 
> react-scripts start 


/root/17-visit-booker-frontend/node_modules/react-scripts/scripts/start.js:33 
const { 
    ^

SyntaxError: Unexpected token { 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:374:25) 
    at Object.Module._extensions..js (module.js:417:10) 
    at Module.load (module.js:344:32) 
    at Function.Module._load (module.js:301:12) 
    at Function.Module.runMain (module.js:442:10) 
    at startup (node.js:136:18) 
    at node.js:966:3 

npm ERR! Linux 4.4.0-81-generic 
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start" 
npm ERR! node v4.2.6 
npm ERR! npm v3.5.2 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] start: `react-scripts start` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] start script 'react-scripts start'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the booking-frontend package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  react-scripts start 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs booking-frontend 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls booking-frontend 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /root/17-visit-booker-frontend/npm-debug.log 

嘗試運行任何npm腳本包括npm run build所有失敗的確切同樣的錯誤引用在每個相同的路線:與npm start項目失敗SyntaxError中的文件:

SyntaxError: Unexpected token { 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:374:25) 
    at Object.Module._extensions..js (module.js:417:10) 
    at Module.load (module.js:344:32) 
    at Function.Module._load (module.js:301:12) 
    at Function.Module.runMain (module.js:442:10) 
    at startup (node.js:136:18) 
    at node.js:966:3 

在我的原始機器上運行相同的腳本,即Mac,則成功。

我試過重新安裝node/npm這不能解決問題。據推測,這是可選的依賴關係導致失敗?

任何幫助表示讚賞。

+0

什麼是/root/17-visit-booker-frontend/node_modules/react-scripts/scripts/start.js:33,第33行? –

+0

線33 - 38:'常量{ choosePort, createCompiler, prepareProxy, prepareUrls, } =需要( '反應-DEV-utils的/ WebpackDevServerUtils');'其中的唯一事情佔用線路33是'常量{'並且每個逗號分隔的項目都在一個新行中。 – Shiri

+0

儘管此引用的行將根據我運行的腳本而改變,但當它碰到大括號時總會失敗。然後使用SyntaxError失敗,並引用上面的堆棧跟蹤,無論腳本失敗,它都是相同的。運行'npm run build'會導致它抱怨:'/root/17-visit-booker-frontend/node_modules/react-scripts/scripts/build.js:60 ({stats,previousFileSizes,warnings})=> { '並指出第一次出現花括號。 – Shiri

回答

3

您正在使用node.js v4,默認情況下它不支持解構語法(const {field1, field2, ....} = object),它無法使用。

你有兩個選擇:

  1. 安裝Node.js的新版本的
  2. 與和諧的標誌
  3. 運行節點,這將使在4.x版此功能
+0

啓用此功能的特定標誌是'--harmony-destructuring',因此運行'node --harmony-destructuring'應該允許使用它。 –

+0

非常感謝!我很驚訝,當我在使用這個問題時,這個結果很少。 – Shiri

相關問題