Support ES Modules with the nodejs14.x runtime
- 主要语言
- Go
- 星标
- 8.8k
- 派生
- 383
- PR 合并指标
- 30 天内没有已合并 PR
描述
## Prerequisites
* [x] I am running the latest version. (`up upgrade`)
* [x] I searched to see if the issue already exists.
* [x] I inspected the verbose debug output with the `-v, --verbose` flag.
* [x] Are you an Up Pro subscriber?
## Description
I am using the [Node.js 14.x runtime](https://aws.amazon.com/fr/about-aws/whats-new/2021/02/aws-lambda-now-supports-node-js-14/).
I can deploy a svelte kit app (with the node adapter) with up but accessing it fails because of the usage of ES Modules (`"type": "module"` in the `package.json` file).
Since Node 14 allows ECMAScript modules natively and without flag, it would be lovely to use them with up with the Node 14.x runtime.
## Steps to Reproduce
To start, I init the [svelte kit](https://kit.svelte.dev/) app:
```shell
npm init svelte@next my-app
cd my-app
npm install
```
Then, the [node adapter](https://github.com/sveltejs/kit/tree/master/packages/adapter-node):
```shell
npm i -D @sveltejs/adapter-node@next
```
Update the `svelte.config.js`: add the import and the adapter:
```
import adapter from '@sveltejs/adapter-node';
export default {
...
kit: {
...
adapter: adapter({
// default options are shown
out: 'build'
})
}
};
```
Then, add the `up.json` file:
```json
{
"name": "example",
"profile": "example",
"lambda": {
"runtime": "nodejs14.x"
},
"regions": ["eu-central-1"],
"stages": {
"production": {
"domain": "example.com"
}
}
}
```
Here is what I get when I open the domain in my browser:
```json
{"message": "Internal server error"}
```
And in up logs:
```
May 24th 05:10:50pm INFO 2021-05-24T15:10:50.444Z undefined ERROR Uncaught Exception {
"errorType": "Error",
"errorMessage": "Must use import to load ES Module: /var/task/_proxy.js\nrequire() of ES modules is not supported.\nrequire() of /var/task/_proxy.js from /var/runtime/UserFunction.js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.\nInstead rename _proxy.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/package.json.\n",
"code": "ERR_REQUIRE_ESM",
"stack": [
"Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/_proxy.js",
"require() of ES modules is not supported.",
"require() of /var/task/_proxy.js from /var/runtime/UserFunction.js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.",
"Instead rename _proxy.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/package.json.",
"",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)",
" at Module.load (internal/modules/cjs/loader.js:928:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:769:14)",
" at Module.require (internal/modules/cjs/loader.js:952:19)",
" at require (internal/modules/cjs/helpers.js:88:18)",
" at _tryRequire (/var/runtime/UserFunction.js:75:12)",
" at _loadUserApp (/var/runtime/UserFunction.js:95:12)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object. (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:1063:30)"
]
}
```
Thanks!
贡献指南
评估
这个 Issue 还没有评估数据。