Javascript Browserify-ParseError:&x27;导入&x27;和';出口';只能与';sourceType:module';

Javascript Browserify-ParseError:&x27;导入&x27;和';出口';只能与';sourceType:module';,javascript,node.js,browserify,Javascript,Node.js,Browserify,我想让通过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'; ^ Par

我想让通过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'
我读了以下内容:通过点击browserify按钮。但是它没有任何帮助(我安装了
npm安装——保存dev babelify babel core——保存精确的
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
{
    "compilerOptions": {
        "target": "ES5",
        "module": "ES2015",
        "declaration": true,
        "lib": ["ES2016", "ES2017", "ES2018", "ES2019", "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/**/*"]
}
tsconfig.js
文件:

export * from './shared';
export * from './client';
export * from './server';
//# sourceMappingURL=index.js.map
{
    "compilerOptions": {
        "target": "ES5",
        "module": "ES2015",
        "declaration": true,
        "lib": ["ES2016", "ES2017", "ES2018", "ES2019", "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,但我不知道它到底需要什么。

这是否回答了您的问题?或者,在您的情况下,您可以更改TSC发出的模块类型:@jornsharpe我确实读过了,没有。不幸的是,我确实读过我能得到的所有其他内容。我尝试添加他们提到的预设。请展示你在问题中的研究,并给出一个答案。@jonrsharpe啊,是的,这可能是更改为commonjs并让browserify的正确方法。发帖并回答,我会接受。这回答了你的问题吗?或者,在您的情况下,您可以更改TSC发出的模块类型:@jornsharpe我确实读过了,没有。不幸的是,我确实读过我能得到的所有其他内容。我尝试添加他们提到的预设。请展示你在问题中的研究,并给出一个答案。@jonrsharpe啊,是的,这可能是更改为commonjs并让browserify的正确方法。张贴和回答,我会接受。