Skip to content

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

@cagross

Description

@cagross

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions