2017-08-31 52 views
0

「絲線行進建立生產」我提前道歉我近似英語:)「語法錯誤:意外的標記{」時:分期

這裏是一個小總結一下: 我們有一個Rails項目4,我們最近添加了一些React組件和React_on_rails gem,所以我們需要將Webpack作爲Asset Pipeline的朋友(是的,我知道,Rails 5的確做得更好)

所以問題是,當我嘗試部署在試圖做yarn run build:production時:

$ NODE_ENV=production webpack -p --config webpack.config.js 
/home/unisc/apps/staging/releases/20170831104131/client/node_modules/react-on-rails/webpackConfigLoader.js:14 
const { join, resolve } = require('path'); 
    ^

SyntaxError: Unexpected token { 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:373:25) 
    at Object.Module._extensions..js (module.js:416:10) 
    at Module.load (module.js:343:32) 
    at Function.Module._load (module.js:300:12) 
    at Module.require (module.js:353:17) 
    at require (internal/module.js:12:17) 
    at Object.<anonymous> (/home/unisc/apps/****_staging/releases/20170831104131/client/webpack.config.js:13:27) 
    at Module._compile (module.js:409:26) 
    at Object.Module._extensions..js (module.js:416:10) 

這裏是我的package.json:

{ 
    "name": "****", 
    "private": true, 
    "scripts": { 
    "build:test": "NODE_ENV=test webpack --config webpack.config.js", 
    "build:production": "NODE_ENV=production webpack --config webpack.config.js", 
    "build:development": "NODE_ENV=development webpack -w --config webpack.config.js" 
    }, 
    "cacheDirectories": ["node_modules", "client/node_modules"], 
    "dependencies": { 
    "babel-cli": "^6.24.1", 
    "babel-core": "^6.24.1", 
    "babel-loader": "^6.3.2", 
    "babel-runtime": "^6.23.0", 
    "babel-polyfill": "^6.23.0", 
    "babel-preset-es2015": "^6.24.1", 
    "babel-preset-react": "^6.24.1", 
    "babel-preset-stage-2": "^6.24.1", 
    "es5-shim": "^4.5.9", 
    "expose-loader": "^0.7.3", 
    "imports-loader": "^0.7.1", 
    "js-yaml": "^3.8.2", 
    "react": "^15.5.4", 
    "react-dom": "^15.5.4", 
    "react-on-rails": "8.0.0", 
    "webpack": "^2.3.3", 
    "webpack-manifest-plugin": "^1.1.0" 
    }, 
    "devDependencies": { 
    } 
} 

和我webpack.config.js:

// For inspiration on your webpack configuration, see: 
// https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client 
// https://github.com/shakacode/react-webpack-rails-tutorial/tree/master/client 

const webpack = require('webpack'); 
const { resolve } = require('path'); 

const ManifestPlugin = require('webpack-manifest-plugin'); 
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader'); 

const configPath = resolve('..', 'config'); 
const { devBuild, manifest, webpackOutputPath, webpackPublicOutputDir } = 
    webpackConfigLoader(configPath); 

const config = { 

    context: resolve(__dirname), 

    entry: { 
    'webpack-bundle': [ 
     'es5-shim/es5-shim', 
     'es5-shim/es5-sham', 
     'babel-polyfill', 
     './app/bundles/registration', 
    ], 
    }, 

    output: { 
    // Name comes from the entry section. 
    filename: '[name]-[hash].js', 

    // Leading slash is necessary 
    publicPath: `/${webpackPublicOutputDir}`, 
    path: webpackOutputPath, 
    }, 

    resolve: { 
    extensions: ['.js', '.jsx'], 
    }, 

    plugins: [ 
    new webpack.EnvironmentPlugin({ 
     NODE_ENV: 'development', // use 'development' unless process.env.NODE_ENV is defined 
     DEBUG: false, 
    }), 
    new ManifestPlugin({ fileName: manifest, writeToFileEmit: true }), 
    ], 

    module: { 
    rules: [ 
     { 
     test: require.resolve('react'), 
     use: { 
      loader: 'imports-loader', 
      options: { 
      shim: 'es5-shim/es5-shim', 
      sham: 'es5-shim/es5-sham', 
      }, 
     }, 
     }, 
     { 
     test: /\.jsx?$/, 
     use: 'babel-loader', 
     exclude: /node_modules/, 
     }, 
    ], 
    }, 
}; 

module.exports = config; 

if (devBuild) { 
    console.log('Webpack dev build for Rails'); // eslint-disable-line no-console 
    module.exports.devtool = 'eval-source-map'; 
} else { 
    console.log('Webpack production build for Rails'); // eslint-disable-line no-console 
} 

我試圖找到沒有成功的同樣的問題...

這命令在我的機器上運行,兩者(我的機器和分段)都具有相同版本的webpack,並且無論如何它們都使用node_modules中的一個。

感謝您的閱讀,並有一個愉快的一天;)

我已經試過:

  • NPM升級,升級紗,消除node_modules並再次嘗試
  • 轉換整個配置文件到ES5,但碰到另一個大括號中的依賴
  • 嘗試移動,刪除.babelrc文件

什麼,我其實是想:

  • 樣子ES6 transpilation的日子不好過
+0

你有'.babelrc'文件嗎? –

+0

哇,你快!這裏是: '{ 「預設」:[「es2015」,「stage-2」,「react」] }' – Bakhah

+0

檢查您調用部署任務的目錄中是否存在'babelrc'。 –

回答

0

定了!

由於Michael Jungo,問題是,在的NodeJS不更新臨時服務器上,所以花括號無法讀取...

謝謝!! 反正我失去了很多時間......