question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: require is not defined

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

35reactions
rationality6commented, Jun 5, 2017

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.

31reactions
loganfsmythcommented, Aug 4, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found