. Advertisement .
..3..
. Advertisement .
..4..
I have just got parseerror: ‘import’ and ‘export’ may appear only with ‘sourcetype: module’ error. My detail error below:
PS D:\Work\dev2qa.com-example-code\PythonExampleProject\html\browserify-example> browserify ./js/test1.js -o build.js
D:\Work\dev2qa.com-example-code\PythonExampleProject\html\browserify-example\js\test1.js:1
import helloFromTest2, { moduleName } from "./test2.js";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Please help me find out the way to solve that problem. I am very grateful for your help. Thanks so much.
The cause: This issue occurs because the test1.js file’s javascript source code syntax is not supported by Browserify. The JS code may be written in ES6+ style. Solution: Therefore, you ought to use Babel to transcompile the javascript code to a lower syntax that Browserify accepts, like es2015. It can fix the error parseerror: ‘import’ and ‘export’ may appear only with ‘sourcetype: module’.
– The javascript source code for the files lib/test1.js and lib/test2.js may be seen on an earlier web browser by opening them in a text editor.