首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >"SyntaxError:意外令牌“当‘纱线运行生成:生产’时

"SyntaxError:意外令牌“当‘纱线运行生成:生产’时
EN

Stack Overflow用户
提问于 2017-08-31 11:44:32
回答 1查看 3.7K关注 0票数 1

我为我的近似英语道歉:)

这里简单回顾一下:我们有一个Rails 4项目,最近我们用React_on_rails gem添加了一些反应组件,所以我们需要实现Webpack作为资产管道的朋友(是的,我知道,Rails 5做得真的更好)

因此,问题是,当我尝试在临时部署时,以及在尝试在其上执行yarn run build:production时:

代码语言:javascript
运行
复制
$ 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:

代码语言:javascript
运行
复制
{
  "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:

代码语言:javascript
运行
复制
// 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的转移是很糟糕的
EN

回答 1

Stack Overflow用户

发布于 2017-08-31 13:37:27

修好了!

多亏了Michael Jungo,问题是nodejs没有在暂存服务器上更新,因此无法读取大括号.

谢谢!!反正我浪费了很多时间..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45980686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档