[英]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.