ES6 import always returns undefined
See original GitHub issueWhy the module can’t be import after babelify? My case: MyModule.js
export class MyModule {
}
After babelify it I got bundle.js.
import {MyModule} from 'bundle';
But MyModule is undefined.
Here is my gulp build
var gulp = require('gulp-help')(require('gulp'));
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var babelify = require('babelify');
var bundleCollapser = require('bundle-collapser/plugin');
var derequire = require('derequire');
var source = require('vinyl-source-stream');
var map = require('vinyl-map');
var buffer = require('vinyl-buffer');
gulp.task('build', 'Builds the library', function (cb) {
var production = $.util.env.type === 'production';
var b = browserify({
debug: !production,
entries: './lib/MyModule.js',
paths: ['./lib']
});
// transform to babel
b.transform(babelify);
// convert bundle paths to IDS to save bytes in browserify bundles
b.plugin(bundleCollapser);
b.bundle()
.on('error', function (err) {
$.util.log($.util.colors.bold('Build Failed!'));
cb(err);
})
.pipe(source('bundle.js'))
.pipe(map(function (code) {
return derequire(code);
}))
.pipe(buffer())
.pipe(gulp.dest('dist')) // for npm distribution
.on('end', function () {
cb();
});
});
My .bebalrc
{
"presets": [
"env"
],
"plugins": [
"transform-class-properties"
]
}
Here is the demo project https://github.com/unbug/js-middleware
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
ES6 modules import is undefined - javascript - Stack Overflow
In essence, when your MyComponent1 is trying to import MyComponent2 via the index file, the index file has not been exported yet so...
Read more >Imports/requires return undefined #11562 - babel/babel - GitHub
I found out that happens when there is a _interopRequireDefault with a file inside the project which defers the resolving of modules or...
Read more >Imported es6 module is undefined during Debug (During Test ...
Undefined variables while debugging must be caused by wrong/missing name mappings in sourcemaps: if the variable is renamed while transpiling/ ...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >Documentation - TypeScript 2.0
Null - and undefined-aware types. TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively.
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
@ksmigiel Search babelify standalone
@unbug Can you be more specific, your answer is really vague. What did you do to arrive at a solution?