gpt4 book ai didi

javascript - 语法错误: 'import' and 'export' may appear only with 'sourceType: module' - Gulp

转载 作者:行者123 更新时间:2023-12-02 22:46:24 29 4
gpt4 key购买 nike

考虑以下两个文件:

app.js

import Game       from './game/game';
import React from 'react';
import ReactDOM from 'react-dom';

export default (absPath) => {
let gameElement = document.getElementById("container");

if (gameElement !== null) {
ReactDOM.render(
<Game mainPath={absPath} />,
gameElement
);
}
}

index.js

import App from './src/app';

gulpfile.js

var gulp        = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var babelify = require("babelify");
var watch = require('gulp-watch');

gulp.task('make:game', function(){
return browserify({
entries: [
'index.js'
]
})
.transform('babelify')
.bundle()
.pipe(source('index.js'))
.pipe(gulp.dest('app/'));
});

错误:

gulp make:game
[13:09:48] Using gulpfile ~/Documents/ice-cream/gulpfile.js
[13:09:48] Starting 'make:game'...

events.js:154
throw er; // Unhandled 'error' event
^
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'

这个错误是什么?我做错了什么?

最佳答案

ESLint 本身不支持这一点,因为这违反了规范。但是如果你使用 babel-eslint 解析器,那么在你的 eslint 配置文件中你可以这样做:

{
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
}
}

另请考虑Github reference docthe answer referred from here .

关于javascript - 语法错误: 'import' and 'export' may appear only with 'sourceType: module' - Gulp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40029113/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com