使用Gitlab-CI,Webpack构建失败

时间:2018-02-14 11:43:14

标签: linux webpack gitlab-ci

当Gitlab-CI运行我的管道时,我在控制台中收到错误:

$ npm run build

> project-name@1.0.0 build /home/gitlab-runner/builds/1e932413/0/namespace/project-name
> webpack

using environment 'development'
Hash: 4eb3a28e1a75bb9f8fb5
Version: webpack 3.11.0
Time: 70ms
   Asset     Size  Chunks             Chunk Names
index.js  2.75 kB       0  [emitted]  main
   [0] ./index.js 261 bytes {0} [built] [failed] [1 error]

ERROR in ./index.js
Module parse failed: Unexpected token (10:2)
You may need an appropriate loader to handle this file type.
| const root = props => {
|   return(
|       <Provider store={store}>
|           <MyComponent {...props}/>
|       </Provider>
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project-name@1.0.0 build: `webpack`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the project-name@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/gitlab-runner/.npm/_logs/2018-02-14T11_07_48_546Z-debug.log
ERROR: Job failed: exit status 1

我真的不知道导致此错误的原因。这是我到目前为止所尝试的:

  • SSH进入服务器并运行webpack会出现同样的错误
  • 工作区中的
  • git status报告无更改
  • 将工作区复制到其他位置并运行webpack正在运行
  • 在服务器上的其他位置克隆新副本并运行webpack也可以

1 个答案:

答案 0 :(得分:2)

我通过改变

中的babel-loader配置解决了这个问题
rules: [
    {
        test: /\.js$/,
        include: path.resolve(__dirname, 'src'),
        exclude: /(node_modules|bower_components|build)/,
        use: {
            loader: 'babel-loader',
            options: {
                presets: ['env']
            }
        }
    },
    ...
]

rules: [
    {
        test: /\.js$/,
        include: path.resolve(__dirname, 'src'),
        exclude: '/node_modules/',
        use: {
            loader: 'babel-loader',
            options: {
                presets: ['env']
            }
        }
    },
    ...
]

https://github.com/babel/babel-loader/issues/370#issuecomment-310378407