<small id='DYbqj'></small><noframes id='DYbqj'>

        <i id='DYbqj'><tr id='DYbqj'><dt id='DYbqj'><q id='DYbqj'><span id='DYbqj'><b id='DYbqj'><form id='DYbqj'><ins id='DYbqj'></ins><ul id='DYbqj'></ul><sub id='DYbqj'></sub></form><legend id='DYbqj'></legend><bdo id='DYbqj'><pre id='DYbqj'><center id='DYbqj'></center></pre></bdo></b><th id='DYbqj'></th></span></q></dt></tr></i><div id='DYbqj'><tfoot id='DYbqj'></tfoot><dl id='DYbqj'><fieldset id='DYbqj'></fieldset></dl></div>

        <legend id='DYbqj'><style id='DYbqj'><dir id='DYbqj'><q id='DYbqj'></q></dir></style></legend>

          <bdo id='DYbqj'></bdo><ul id='DYbqj'></ul>
        <tfoot id='DYbqj'></tfoot>

        SyntaxError: 'import' 和 'export' 可能只出

        时间:2023-05-28
      1. <small id='gYgOp'></small><noframes id='gYgOp'>

          <tbody id='gYgOp'></tbody>
          <i id='gYgOp'><tr id='gYgOp'><dt id='gYgOp'><q id='gYgOp'><span id='gYgOp'><b id='gYgOp'><form id='gYgOp'><ins id='gYgOp'></ins><ul id='gYgOp'></ul><sub id='gYgOp'></sub></form><legend id='gYgOp'></legend><bdo id='gYgOp'><pre id='gYgOp'><center id='gYgOp'></center></pre></bdo></b><th id='gYgOp'></th></span></q></dt></tr></i><div id='gYgOp'><tfoot id='gYgOp'></tfoot><dl id='gYgOp'><fieldset id='gYgOp'></fieldset></dl></div>

              <bdo id='gYgOp'></bdo><ul id='gYgOp'></ul>
            • <legend id='gYgOp'><style id='gYgOp'><dir id='gYgOp'><q id='gYgOp'></q></dir></style></legend>
              <tfoot id='gYgOp'></tfoot>
                  本文介绍了SyntaxError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - Gulp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  考虑以下两个文件:

                  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'
                  

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

                  推荐答案

                  旧版本的 Babel 提供了开箱即用的一切.较新的版本要求您安装安装所需的任何插件.首先,您需要安装 ES2015 预设.

                  Older versions of Babel came with everything out of the box. The newer version requires you install whichever plugins your setup needs. First, you'll need to install the ES2015 preset.

                  npm install babel-preset-es2015 --save-dev
                  

                  接下来,你需要告诉 babelify 使用你安装的预设.

                  Next, you need to tell babelify to use the preset you installed.

                  return browserify({ ... })
                    .transform(babelify.configure({
                      presets: ["es2015"]
                    }))
                    ...
                  

                  来源

                  这篇关于SyntaxError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - Gulp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Gulps gulp.watch 不会为新文件或已删除文件触发? 下一篇:使用 Gulp 按顺序连接脚本

                  相关文章

                  最新文章

                  <i id='ziUNr'><tr id='ziUNr'><dt id='ziUNr'><q id='ziUNr'><span id='ziUNr'><b id='ziUNr'><form id='ziUNr'><ins id='ziUNr'></ins><ul id='ziUNr'></ul><sub id='ziUNr'></sub></form><legend id='ziUNr'></legend><bdo id='ziUNr'><pre id='ziUNr'><center id='ziUNr'></center></pre></bdo></b><th id='ziUNr'></th></span></q></dt></tr></i><div id='ziUNr'><tfoot id='ziUNr'></tfoot><dl id='ziUNr'><fieldset id='ziUNr'></fieldset></dl></div>
                    • <bdo id='ziUNr'></bdo><ul id='ziUNr'></ul>

                  1. <legend id='ziUNr'><style id='ziUNr'><dir id='ziUNr'><q id='ziUNr'></q></dir></style></legend>

                      <tfoot id='ziUNr'></tfoot>
                    1. <small id='ziUNr'></small><noframes id='ziUNr'>