Skip to content
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

Continued problems with issue #103 ('import' and 'export' may appear only with 'sourceType: module') #294

Open
cagross opened this issue Aug 16, 2020 · 4 comments

Comments

@cagross
Copy link

cagross commented Aug 16, 2020

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's babel.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.

@nicolas-hili
Copy link

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

@cagross cagross changed the title Continued problems with issue #104 ('import' and 'export' may appear only with 'sourceType: module') Continued problems with issue #10 ('import' and 'export' may appear only with 'sourceType: module') Aug 16, 2020
@cagross cagross changed the title Continued problems with issue #10 ('import' and 'export' may appear only with 'sourceType: module') Continued problems with issue #103 ('import' and 'export' may appear only with 'sourceType: module') Aug 16, 2020
@danielgestwa
Copy link

danielgestwa commented May 12, 2022

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

@arun3528
Copy link

Any update on this issue i am seeing the same when i a, trying to run karma with browserify with babelify

@arun3528
Copy link

Did you try adding the extensions: ['.ts', '.js'] to babelify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants