简体   繁体   English

使用 es6 模块:未捕获的 ReferenceError:define 未定义

[英]using es6 modules: Uncaught ReferenceError: define is not defined

I want to use es6 modules and I installed babel plugin (es2015-modules-amd) for them.我想使用 es6 模块,并为它们安装了 babel 插件(es2015-modules-amd)。 But what I write in the module is not imported to the main file, console errors: " Uncaught ReferenceError: define is not defined" at the first attempt to import anything.但是我在模块中写的内容没有导入到主文件中,在第一次尝试导入任何内容时,控制台错误:“未捕获的引用错误:定义未定义”。 Same thing has happened when I tried to use common.js with those require statements, console just has pointed, the error and that require is not defined too.当我尝试将 common.js 与那些 require 语句一起使用时,也发生了同样的事情,控制台刚刚指出,错误和那个 require 也没有定义。 What is it?它是什么?

我必须得到一个模块捆绑器,使用它后,一切顺利

i had to install我必须安装

npm i -D @babel/plugin-transform-modules-amd

and use .babelrc file并使用.babelrc文件

{
  "plugins": [
    "transform-es2015-modules-amd"
  ]
}

Another method solved my problem when it came up "define is not defined" error from babel:当 babel 出现“define is not defined”错误时,另一种方法解决了我的问题:

npm install --save-dev browserify 
browserify input.js > output.js

Although it's browserify easily solved the problem.虽然它的browserify轻松解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Uncaught ReferenceError: “function” is not defined ES6 模块 - Uncaught ReferenceError: “function” is not defined ES6 Modules es6未捕获的ReferenceError:未定义类 - es6 Uncaught ReferenceError: class is not defined 设置WebPack和Babel以使用ES6模块,但获取Uncaught ReferenceError:函数未定义 - Setting WebPack & Babel to use ES6 modules but gets Uncaught ReferenceError: function is not defined ES6模块“Uncaught ReferenceError:函数未在HTMLButtonElement.onclick中定义” - ES6 module “Uncaught ReferenceError: function is not defined at HTMLButtonElement.onclick” ES6 + jQuery + Bootstrap - 未捕获的ReferenceError:jQuery没有定义? - ES6 + jQuery + Bootstrap - Uncaught ReferenceError: jQuery is not defined? 带有 axios 的 es6 异步模块 - 参考错误:未定义要求 - es6 async modules with axios - ReferenceError: require is not defined 未被捕获的ReferenceError:未定义 - Uncaught ReferenceError: define is not defined 如何使用ES6导入插件? (获取ReferenceError:未定义插件) - How to import a plugin using ES6? (Getting ReferenceError: Plugin is not defined) 在 Google Apps Script => ReferenceError 中使用转译的 ES6:未定义“SomeClass” - Using transpiled ES6 in Google Apps Script => ReferenceError: "SomeClass" is not defined 未捕获ReferenceError:define未定义打字稿 - Uncaught ReferenceError: define is not defined typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM