Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ES Modules with the nodejs14.x runtime #827

Open
4 tasks done
SiegfriedEhret opened this issue May 24, 2021 · 0 comments
Open
4 tasks done

Support ES Modules with the nodejs14.x runtime #827

SiegfriedEhret opened this issue May 24, 2021 · 0 comments

Comments

@SiegfriedEhret
Copy link

SiegfriedEhret commented May 24, 2021

Prerequisites

  • I am running the latest version. (up upgrade)
  • I searched to see if the issue already exists.
  • I inspected the verbose debug output with the -v, --verbose flag.
  • Are you an Up Pro subscriber?

Description

I am using the Node.js 14.x runtime.

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 app:

npm init svelte@next my-app
cd my-app
npm install

Then, the node adapter:

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:

{
	"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:

{"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.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1063:30)"
  ]
}

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant