Uncaught ReferenceError: require is not defined
See original GitHub issueHi,
I am experimenting with ES7 generators in my project. I followed these instructions https://www.npmjs.com/package/gulp-babel#runtime to install the required gulp-babel plugin.
I am seeing an error in my console as follows when I reload the page:
main.js:3 Uncaught ReferenceError: require is not defined
Inside main.js:3
there is the line:
var _promise = require('babel-runtime/core-js/promise');
The task within my gulpfile.js
looks like this:
gulp.task('scripts-dev', () => {
return gulp
.src('./assets/scripts/**/*')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(babel({
presets: ['es2015'],
plugins: ['transform-runtime']
}))
.pipe(gulp.dest(dest.scripts));
});
Is there another plugin I need to install to get this working?
For reference, the branch I am experimenting with for my project can be seen here.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Client on Node.js: Uncaught ReferenceError: require is not ...
However, require is not defined on the client side, and it throws an error of the form Uncaught ReferenceError: require is not defined...
Read more >ReferenceError: require is not defined in JavaScript - Stack Diary
The "ReferenceError: require is not defined" error occurs when the require function is used in a JavaScript file that is intended to be ......
Read more >How to fix "require is not defined" in JavaScript / Node.js?
In our case, the error message is “require is not defined” which indicates the problem is with the variable or method named “require”....
Read more >How To Fix ReferenceError require is not defined in JavaScript
In this case, check your package.json file for an property called type . If that is set to module , ES6 modules will...
Read more >Fix "require is not defined" in JavaScript/Node - Stack Abuse
You try to use the require statement in the browser · You try to use require in Node when ES modules are specified...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I solved this error with this way. change babel to latest preset. I read babel documentations
https://github.com/babel/babel-preset-env
.pipe(babel({ presets: [‘env’] }))
and than install babel polyfill
and gonna everyhings work fine.
transform-runtime
is by definition modular. If you’re using it, you need to be using your code in an environment that supports modules, so either Node or client-side with Webpack or Browserify.