5

I want to use es6 modules and I installed babel plugin (es2015-modules-amd) for them. 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. What is it?

6
  • What AMD module loader are you using? It should provide the define function.
    – Bergi
    Commented Apr 10, 2016 at 15:05
  • I installed es2015-modules-amd es2015-modules-commonjs for that. Is it what you mean?
    – Alex Buddy
    Commented Apr 10, 2016 at 15:09
  • or do I need to use something else?
    – Alex Buddy
    Commented Apr 10, 2016 at 15:11
  • Just googled browserify. Should I use this one? Or what is the best module loader in your opinion?
    – Alex Buddy
    Commented Apr 10, 2016 at 15:14
  • 1
    no I didn't use any of these, so it's prob the issue
    – Alex Buddy
    Commented Apr 10, 2016 at 20:24

3 Answers 3

0

I had to get a module bundler, after I used it, everything went fine

0

i had to install

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

and use .babelrc file

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

Another method solved my problem when it came up "define is not defined" error from babel:

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

Although it's browserify easily solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.