-
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'import' and 'export' may appear only with 'sourceType: module' #103
Comments
Do you have a stack trace or some more detailed error output? My money is on |
I log
What would be the equivalent in
but my modules are not found 😞 |
@maiermic Yeah, I would suggest trying one of the following:
|
I tried |
@maiermic Great! You're welcome. |
@maiermic In my case it happens only when I use extensions option. This dosen't works: let fs = require('fs'),
browserify = require('browserify'),
babelify = require('babelify'),
path = require('path');
console.log(__dirname)
browserify({
debug: true,
extensions: ['es6'],
entries: ['src/test.es6']
})
.transform(babelify.configure({
extensions: ['es6'],
sourceMapRelative: path.resolve(__dirname, 'src')
}))
.bundle()
.pipe(fs.createWriteStream("src/bundle.js")); While this does works: let fs = require('fs'),
browserify = require('browserify'),
babelify = require('babelify'),
path = require('path');
console.log(__dirname)
browserify({
debug: true,
//extensions: ['es6'],
//entries: ['src/test.es6']
entries: ['src/test.js']
})
.transform(babelify.configure({
//extensions: ['es6'],
sourceMapRelative: path.resolve(__dirname, 'src')
}))
.bundle()
.pipe(fs.createWriteStream("src/bundle.js")); The only difference is with extensions nothing else. |
@anshulguleria, @maiermic's problem was caused by the |
@jmm Thanks. That was exactly the problem. Didn't realizes it was this small.... wasted hours on it. |
@anshulguleria You're welcome. Yeah, that's frustrating :( There was just a PR merged into Browserify to automatically prepend the |
I am getting same error again.
This time I was configuring browserify from package.json "browserify": {
"transform": [
[
"babelify",
{
"sourceMapRelative": "$PWD/src/js"
}
]
]
} and trying to use npm scripts Versions "babelify": "^7.0.2",
"browserify": "^12.0.1", @jmm Any idea why? |
@anshulguleria It's because you're using |
@jmm Thanks. "browserify": {
"transform": [
[
"babelify",
{
"sourceMapRelative": "$PWD/src/js",
"presets": ["es2015"]
}
]
]
} |
I am getting same error after updating to latest version of babel & node.
I use gulp. var appBundler = browserify({
entries: [options.src],
extension: [
'jsx',
'json',
'js',
'es6'
],
transform: [
[
"babelify"
]
],
debug: options.development,
cache: {},
packageCache: {},
fullPaths: options.development
}); .babelrc |
Ok, I added es2015 to babelrc before stage-1 and it does not throw that error, however things like es6 bind ::this.somefunc() throw syntaxerror... |
@TheDeveloperXYZ Check out the support resources listed in the |
Hi, i had the same problem, but switching back to version babelify@6.1.2 solved this problem. Could you try it out? |
@Thomas-P -- been fighting with this issue for a couple days now -- rolling back to 6.1.2 fixed it. (see: https://github.com/xirvr/xirvr.com) |
@Thomas-P, @xirvr have you tried installing and using the presets? |
Hi, I'm having a similar problem and getting the error: Syntax error: My gulp.js file is as follows: var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
gulp.task('browserify', function() {
return browserify()
.require('js/app.js', { entry: true,
extensions: ['.js'],
debug: true
})
.transform(babelify, {presets: ["stage-0", "react"]})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('js'));
});
gulp.task('watch', function() {
gulp.watch('**/*.js', ['browserify']);
}); |
@zertosh yes, i tried, but it hasn't work for me. But I'm very happy, that the downgrade work. |
@Thomas-P, can you provide me with a repo that I can use to reproduce the issue? |
Hi, |
@sousk you have no plugins or presets configured. |
@sousk the name of your repro repo doesn't match the dep on babelify -- what version are you actually having a problem with? |
@jmm You're right. That's not a issue but just because I missed to set presets configuration. |
@jmm I got an error at babelify@7.2.0 (without presets). |
It's pretty clear that people aren't reading the README after doing a major version upgrade. I'm going to add a one-time warning if babel throws and there are no presets/plugins specified. @sebmck Is there any use to running babel w/o any plugins? (besides to generate an AST) |
Actually that's not going to work because it's not babel throwing an error, it's browserify. |
@zertosh You could just be cheap and do |
$ npm install babel-preset-es2015 and in gulpfile set: It's work for me. |
@joeyisking I had your same problem, and realized we need both stage-0 AND es2015: |
@danehansen It worked! You're a dead-set legend |
I managed to get this working using the following commands:
And then in my gulpfile.js
|
I believe this is something to do with newer update of babelify. I had one project working just fine with gulp.task('watchify', function () {
var args = merge(watchify.args, { debug: true })
var bundler = watchify(browserify('./src/js/main.js', args)).transform(babelify, {})
bundle_js(bundler)
bundler.on('update', function () {
bundle_js(bundler)
})
})
function bundle_js(bundler) {
return bundler.bundle()
.on('error', gutil.log)
.pipe(source('main.js'))
.pipe(buffer())
.pipe(gulp.dest('js'))
.pipe(sourcemaps.init({ loadMaps: true }))
// capture sourcemaps from transforms
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('js'))
} And I used same code in new poject, and it always threw Then I realised that in the new project, it had babelify |
news? (I also had to downgrade to 6.3.0) |
If you're getting this error then you most certainly have a misconfigured Babel 6 setup. Babel 6 is very different from Babel 5. It's not a drop-in replacement. The readme has more information. |
I switched from
6to5ify@3.1.2
tobabelify@6.1.3
and at the same time upgradedbrowserify
from6.3.4
to10.2.6
,watchify
from2.3.0
to3.2.3
andremapify
from1.4.3
to2.0.3
. Now I get several build errors:'import' and 'export' may appear only with 'sourceType: module'
My build file looks more or less like this:
The text was updated successfully, but these errors were encountered: