typescript 无服务器错误:“import”和“export”只能与“sourceType:模块'

jvlzgdj9  于 2023-05-30  发布在  TypeScript
关注(0)|答案(1)|浏览(317)

当执行命令时:serverless deploy,我得到以下错误

Running "serverless" from node_modules

Deploying my-project to stage dev (us-east-1)
Optimize: starting engines
Optimize: my-project-dev-main

× Stack onfield-api-v3-dev failed to deploy (12s)
Environment: win32, node 16.10.0, framework 3.30.1 (local) 3.30.1v (global), plugin 6.2.3, SDK 4.3.2
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
'import' and 'export' may appear only with 'sourceType: module'

我对.eslintrc.js、serverless.yml和browserify中的配置选项进行了演练,只得到了更多的错误和死胡同

r9f1avp5

r9f1avp51#

为了解决这个问题,我只能建议直接将console.log()错误添加到node_module内部的serverless-optimize插件中。在这里,您应该会看到类似这样的内容:

node_modules/pg-cloudflare/dist/index.js:1\n' +
    "import { EventEmitter } from 'events';\n" +
    '^\n' +
    "ParseError: 'import' and 'export' may appear only with 'sourceType: module'",

然后,只需添加为您在serverless配置中优化*external**对象带来问题的包即可。

相关问题