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

使用ES2015报错 #131

Closed
ikarosu opened this issue Jan 13, 2016 · 9 comments
Closed

使用ES2015报错 #131

ikarosu opened this issue Jan 13, 2016 · 9 comments

Comments

@ikarosu
Copy link

ikarosu commented Jan 13, 2016

npm使用build报错

ERROR in ./src/main.js

E:\bzys\Bzys\Bzys\src\main.js
  1:2  error  Parsing error: Illegal import declaration

✖ 1 problem (1 error, 0 warnings)


ERROR in ./src/main.js
Module parse failed: E:\bzys\Bzys\Bzys\node_modules\babel-loader\index.js!E:\bzys\Bzys\Bzys\node_modules\eslint-loader\index.js!E:\bzys\Bzys\Bzys\src\main.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import Vue from 'vue';
| import NavT from './components/navigation.vue';
| // var Vue = require('vue')

我的package.json

...
"devDependencies": {
    "babel-core": "^6.4.0",
    "babel-loader": "^6.2.1",
    "babel-plugin-transform-runtime": "^6.4.0",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-stage-0": "^6.3.13",
    "babel-runtime": "^5.8.34",
    "css-loader": "^0.23.1",
    "eslint": "^1.10.3",
    "eslint-loader": "^1.2.0",
    "file-loader": "^0.8.5",
    "function-bind": "^1.0.2",
    "inject-loader": "^2.0.1",
    "jade": "^1.11.0",
    "jasmine-core": "^2.4.1",
    "karma": "^0.13.19",
    "karma-jasmine": "^0.3.6",
    "karma-phantomjs-launcher": "^0.2.3",
    "karma-spec-reporter": "0.0.23",
    "karma-webpack": "^1.7.0",
    "less-loader": "^2.2.2",
    "phantomjs": "^1.9.19",
    "stylus-loader": "^1.4.3",
    "template-html-loader": "0.0.3",
    "url-loader": "^0.5.7",
    "vue-hot-reload-api": "^1.2.2",
    "vue-html-loader": "^1.1.0",
    "vue-loader": "^8.0.2",
    "vue-style-loader": "^1.0.0",
    "webpack": "^1.12.11",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "vue": "^1.0.14"
  }

main.js

import Vue from 'vue';
import NavT from './components/navigation.vue';
// var Vue = require('vue')
// var NavT = require('./components/navigation.vue')

new Vue({
  el: 'body',
  components: { 
    "nav-t":NavT
  }
})

webpack配置是和这个项目一样的,只要用下面注释那两句就正常

@yyx990803
Copy link
Member

你没给 js 文件配置 babel-loader 吧

@ikarosu
Copy link
Author

ikarosu commented Jan 13, 2016

@yyx990803 因为我刚学习使用这个,我的整个build目录都是用的这个项目的,没有改过。你说的配置是不是webpack.base.config.js 下的

    {
        test: /\.js$/,
        loader: 'babel!eslint',
        // make sure to exclude 3rd party code in node_modules
        exclude: /node_modules/
    }

@yyx990803
Copy link
Member

你的 Node 什么版本?

@ikarosu
Copy link
Author

ikarosu commented Jan 13, 2016

@yyx990803 4.2.4,不能用吗

@yyx990803
Copy link
Member

试试看把 'babel!eslint' 改成 'babel-loader!eslint-loader'

@ikarosu
Copy link
Author

ikarosu commented Jan 14, 2016

@yyx990803 改了也不行,我因为刚接触这些管理工具,也捣鼓一天了,还是没弄出个所以然

@ikarosu
Copy link
Author

ikarosu commented Jan 14, 2016

我做了很多东西,现在好了,不知道是不是卸载了重装node,又或是把npm升级到3的原因。。谢谢

@Relsoul
Copy link

Relsoul commented Mar 29, 2016

@ikarosu 我来补坑...今天遇到这个问题了.莫名其妙的..所有依赖都是一样的就是出错 结果在这个文件中 .babelrc
{ "presets": ["es2015"], "plugins": ["transform-runtime"] }
给babel加上这样一些参数就行了...

@miansword
Copy link

我試過,把nodejs升級到最新版就可以了。。。。

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

4 participants