Open cagross opened 4 years ago
Hello,
I just ran into the same issue and tried all the options above with no success. I really look forward to a solution.
My Browserify command:
browserify --debug index.js -o dist/bundle.js -s ns -t [ babelify --presets [ @babel/preset-env ] ]
The output:
export * from './src/test.js'; ^ ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Browserify: v16.5.2 Babelify: v10.0.0
Nicolas
Same problem, I tried Babel 7 and 6. After Pinia installation in my Vue project (without vue-cli) and adding import { createPinia, PiniaVuePlugin } from 'pinia'
. When I'm removing this import line, everything works fine.
Error:
[...]/node_modules/@vue/devtools-api/lib/esm/index.js:1
import { getTarget, getDevtoolsGlobalHook, isProxyAvailable } from './env';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Config:
"browserify": {
"transform": [
[
"babelify",
{
"global": true,
"ignore": ["/^(?!.*\/node_modules\/app\/)/"],
"presets": [
"babel-preset-env",
"babel-preset-es2015"
]
}
]
]
}
Build:
browserify src/main.js -o dist/js/app.js
Any update on this issue i am seeing the same when i a, trying to run karma with browserify with babelify
Did you try adding the extensions: ['.ts', '.js'] to babelify
Hello. This is a follow up to an existing (but closed) issue (#103). I am having the same issue. I've tried the suggestions in #103, but still cannot resolve the issue (see below). Are the solutions in that issue still relevant, or have they become obsolete?
In my case, the Browserify command is:
node_modules/.bin/browserify www/js/functions.js test/tape.test.js -t [ babelify ] --outfile test/test-bundle.js
It is failing with the error:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (4819:0) while parsing C:\Users\snarl\Orbis\osatest\node_modules\fetch-mock\esm\client.js while parsing file: C:\Users\snarl\Orbis\osatest\node_modules\fetch-mock\esm\client.js
My Attempts To Resolve
--From #103, I tried installing the package
babel-preset-es2015
then running the command:node_modules/.bin/browserify www/js/functions.js test/tape.test.js -t [ babelify --presets [ es2015 ] ] --outfile test/test-bundle.js
The previous error was gone, but it failed with a new error:
Error: Plugin/Preset files are not allowed to export objects, only functions. In C:\Users\snarl\Orbis\osatest\node_modules\babel-preset-es2015\lib\index.js while parsing file: C:\Users\snarl\Orbis\osatest\test\tape.test.js
A few Stack Overflow posts (example) seemed to indicate that this was because I was using
babel-preset-es2015
, and had to eschew it in favor of a different package;@babel/preset-env
I've removed the old package, and installed the new package. But the Browserify command is back to failing with the original import/export error.--With
@babel/preset-env
installed, I tried three different configurations in my project'sbabel.config.js
file (see pastebin here), but none had any effect on the issue. Those suggestions were taken from the @babel/preset-env page.--With
@babel/preset-env
installed, I tried using the following command from the command line, but there was no change in the result.node_modules/.bin/browserify www/js/functions.js test/tape.test.js -t [ babelify --presets [ es2015 ] ] --outfile test/test-bundle.js
--To see the code in each of my JS files, please see this pastebin.
FYI I am using Browserify v16.5.1 and Babelify v10.0.0.
Thanks in advance.