Browserify-ParseError:“导入”和“导出”可能仅与“ sourceType:模块”一起出现

问题描述

我希望使TypeScript转换为JavaScript的代码能够在浏览器中运行:

ka@Karl-Laptop MINGW64 ~/Development/async (km/client-library)
$ npx browserify ./dist/index.js -t babelify -o ./dist/bundle.js

C:\Users\karl\Development\async\dist\index.js:1
export * from './shared';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

我阅读了以下内容https://babeljs.io/setup#installation通过单击browserify按钮。但这根本没有帮助(我安装了npm install --save-dev babelify babel-core --save-exact并运行了npx browserify ./dist/index.js -t babelify -o ./dist/bundle.js,同样的错误)。

./dist/index.js文件

export * from './shared';
export * from './client';
export * from './server';
//# sourceMappingURL=index.js.map

tsconfig.js文件

{
    "compilerOptions": {
        "target": "ES5","module": "ES2015","declaration": true,"lib": ["ES2016","ES2017","ES2018","ES2019","ES2020","dom"],"moduleResolution": "node","sourceMap": true,"outDir": "./dist/","removeComments": true,"esModuleInterop": true,"baseUrl": ".","resolveJsonModule": true,"strict": true,"noEmitOnError": true,"noFallthroughCasesInSwitch": true,"noImplicitReturns": true,"types": ["node","jest"]
    },"exclude": ["./dist/","./coverage/","./report/"],"include": ["./src/**/*"]
}

因此从TypeScript-> Javascript-> ES5。像往常一样,我猜测需要配置Babel,但是我对它的确切需求却一无所知。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)