在webpack中使用导入时出错。未捕获到的SyntaxError:意外令牌{

时间:2018-12-25 20:12:03

标签: javascript webpack

我对webpack有问题。我正在使用webpack-dev-server,但是当我尝试运行它时,我却遇到了这个错误SyntaxError: Unexpected token {,试图从昨天开始找出错误,但是没有运气。

我已经尝试导出其他文件的默认设置,但导入时仍然遇到相同的问题。

./ sort.js 这是我的出口

     export {descend, ascend};

./ index.js 这是我的进口

    import {descend, ascend} from './js/insertion_sort';

./ babelrc 这是通天塔

    {
      "presets": [["@babel/preset-env"]]
    }

webpack.config.js 这是我的webpack配置

const path = require('path');

const path = require('path');

module.exports = {
 entry: './src/index.js',
 output: {
 path: path.resolve(__dirname, 'dist'),
 filename: 'bundle.js',
 publicPath: '/'
},
module: {
 rules: [
  {test: /\.scss$/, use: 'scss-loader'},
  {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
 ]
},
devServer: {
 contentBase: './'
 }
};

im不使用捆绑包。我只是使用索引文件作为我的主文件。

更新

伙计们,这太奇怪了。我做了什么。在我的html.index上,这是我将脚本标签从<script src="./src/index.js"></script>更改为<script src="./bundle.js"></script>然后工作的原因。但是在我的package.json上我还没有构建它。我只是在运行它。 "start": "webpack-dev-server --mode development --hot"尚未到期时,webpack现在如何在bundle.js处寻找。疯了

0 个答案:

没有答案
相关问题