Node.js 我无法在我的代码中使用ecma6导入获取错误“;意外令牌导入“;
以下是我用于生成虚拟bundle.js的webpack.config.js代码:-Node.js 我无法在我的代码中使用ecma6导入获取错误“;意外令牌导入“;,node.js,reactjs,webpack,babeljs,Node.js,Reactjs,Webpack,Babeljs,以下是我用于生成虚拟bundle.js的webpack.config.js代码:- var webpack = require('webpack'); var path = require('path'); module.exports = { devtool :'inline-source-map', //this give us the line no. incase of error entry:[ '
var webpack = require('webpack');
var path = require('path');
module.exports = {
devtool :'inline-source-map', //this give us the line no. incase of error
entry:[
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/only-dev-server',
'./src'
], //this is where webpack look for the files
output : {
path : path.join(__dirname, 'build'),
filename: 'bundle.js'
}, //this is where webpack create the virtual output
resolve: {
modulesDirectories :['node_modules','src'], //this is where webpack look for module directories
extensions : ['','.js'], // this is the extension for which webpack look for
},
module:{
loader :[
{
test: /\.jsx?$/, //this is to for we can use jsx file if not js file
exclude: /node_modules/, //the part which are not included in our app build
//loader: 'babel-loader'
loaders : ['react-hot','babel-loader','babel?presets[]=react,presets[]=es2015'], // the module which are used to load our app
}
]
},
plugins:[
new webpack.HotModuleReplacementPlugin(), //for live reloading
new webpack.NoErrorsPlugin() // stop app to run if there is any error
]
}
let工作正常,但这些ECMAScript 6关键字(如class和import)不起作用
网页1.13.1
节点v6.3.1
npm 3.10.3
package.json
{
"name": "react-todos",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"react": "^15.3.0",
"react-dom": "^15.3.0"
},
"devDependencies": {
"babel-cli": "^6.11.4",
"babel-core": "*",
"babel-loader": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"react-hot-loader": "*",
"webpack": "*",
"webpack-devserver": "*"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
我的index.js代码:-
import React from 'react';
import { render } from 'react-dom';
import App from 'component/app';
console.log("hiii")
render(<App />, document.getElementById('app'))
从“React”导入React;
从'react dom'导入{render};
从“组件/应用程序”导入应用程序;
控制台日志(“hiii”)
render(,document.getElementById('app'))
看起来webpack没有加载您的加载程序。查看您的webpack配置文件,我发现一个可能的问题,它可能会阻止webpack无法正确加载加载程序。模块loader
字段缺少结尾s
。Webpack需要一个loaders
字段,而您提供的是被忽略的loader
module: {
loaders: [
^
这是微妙的,但可能是原因