Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token: name (path) [./cfg/base.js:2,0] when running dist #336

Open
Mxxim opened this issue Apr 12, 2017 · 0 comments

Comments

@Mxxim
Copy link

Mxxim commented Apr 12, 2017

npm run dist, it happens error:

ERROR in app.js from UglifyJs
SyntaxError: Unexpected token: name (path) [./cfg/base.js:2,0]

The line happens error:

let path = require('path');

I think UglifyJs cant parse let, so it throws SyntaxError. And I know UglifyJs can't parse ES6, but I have used babel to transform ES6 into ES5,

my package.json:

  "devDependencies": {
    "axios": "^0.15.3",
    "babel-core": "^6.0.0",
    "babel-eslint": "^6.0.0",
    "babel-loader": "^6.0.0",
    "babel-polyfill": "^6.3.14",
    "babel-preset-es2015": "^6.0.15",
    "babel-preset-react": "^6.0.15",
    "babel-preset-stage-0": "^6.5.0",
    "bower-webpack-plugin": "^0.1.9",
    "chai": "^3.2.0",
    "classnames": "^2.2.5",
    "copyfiles": "^1.0.0",
    "css-loader": "^0.23.0",
    "eslint": "^3.0.0",
    "eslint-loader": "^1.0.0",
    "eslint-plugin-react": "^6.0.0",
    "file-loader": "^0.9.0",
    "glob": "^7.0.0",
    "isparta-instrumenter-loader": "^1.0.0",
    "jquery": "^3.2.1",
    "karma": "^1.0.0",
    "karma-chai": "^0.1.0",
    "karma-coverage": "^1.0.0",
    "karma-mocha": "^1.0.0",
    "karma-mocha-reporter": "^2.0.0",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-sourcemap-loader": "^0.3.5",
    "karma-webpack": "^1.7.0",
    "minimist": "^1.2.0",
    "mocha": "^3.0.0",
    "node-sass": "^4.5.1",
    "null-loader": "^0.1.1",
    "open": "0.0.5",
    "phantomjs-prebuilt": "^2.0.0",
    "postcss-loader": "^1.3.3",
    "react-addons-test-utils": "^15.0.0",
    "react-alert": "^1.0.14",
    "react-bootstrap": "^0.30.8",
    "react-bootstrap-table": "^3.1.6",
    "react-hot-loader": "^1.2.9",
    "react-modal": "^1.7.3",
    "react-s-alert": "^1.2.2",
    "rimraf": "^2.4.3",
    "rodal": "^1.4.1",
    "sass-loader": "^5.0.1",
    "style-loader": "^0.13.0",
    "url-loader": "^0.5.6",
    "webpack": "^1.12.0",
    "webpack-dev-server": "^1.12.0"
  },
  "dependencies": {
    "core-js": "^2.0.0",
    "normalize.css": "^4.0.0",
    "react": "^15.0.0",
    "react-dom": "^15.0.0",
    "react-redux": "^5.0.3",
    "react-router": "^4.0.0",
    "react-router-dom": "^4.0.0",
    "redux": "^3.6.0",
    "redux-thunk": "^2.2.0"
  }

my .babelrc:

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ]
}

my default.js:

/**
 * Function that returns default values.
 * Used because Object.assign does a shallow instead of a deep copy.
 * Using [].push will add to the base array, so a require will alter
 * the base array output.
 */
'use strict';

const path = require('path');
const srcPath = path.join(__dirname, '/../src');
const dfltPort = 8000;

/**
 * Get the default modules object for webpack
 * @return {Object}
 */
function getDefaultModules() {
  return {
    preLoaders: [
      {
        test: /\.(js|jsx)$/,
        include: srcPath,
        loader: 'eslint-loader'
      }
    ],
    loaders: [
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader!postcss-loader'
      },
      {
        test: /\.sass/,
        loader: 'style-loader!css-loader!postcss-loader!sass-loader?outputStyle=expanded&indentedSyn'
      },
      {
        test: /\.scss/,
        loader: 'style-loader!css-loader!postcss-loader!sass-loader?outputStyle=expanded'
      },
      {
        test: /\.less/,
        loader: 'style-loader!css-loader!postcss-loader!less-loader'
      },
      {
        test: /\.styl/,
        loader: 'style-loader!css-loader!postcss-loader!stylus-loader'
      },
      {
        test: /\.(png|jpg|gif|woff|woff2|eot|ttf|svg)$/,
        loader: 'url-loader?limit=8192' 
      },
      {
        test: /\.(mp4|mp3|ogg|svg)$/,
        loader: 'file-loader'
      }
    ]
  };
}

module.exports = {
  srcPath: srcPath,
  publicPath: '/assets/',
  port: dfltPort,
  getDefaultModules: getDefaultModules
};

Node version: v6.9.1
NPM version: v3.10.8

Can you tell me how to fix it please? Thanks in advance.😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant