Skip to content

@sveltejs/adapter-node failure due to ES version #1667

@Darth-Knoppix

Description

@Darth-Knoppix

Describe the bug
When creating the skeleton project with TypeScript and using @sveltejs/adapter-node, the build succeeds with warnings and fails to run when using node build.

Logs

Build warning
> Using @sveltejs/adapter-node
 > .svelte-kit/node/index.js:18:31: warning: "import.meta" is not available in the configured target environment ("es2019") and will be empty
    18 │ global.require = createRequire(import.meta.url);~~~~~~~~~~~
   tsconfig.json:6:12: note: The target environment was set to "es2019" here
     6 │     "target": "es2019",
       ╵               ~~~~~~~~

 > .svelte-kit/node/index.js:15792:40: warning: "import.meta" is not available in the configured target environment ("es2019") and will be empty
    15792 │ const __dirname = dirname(fileURLToPath(import.meta.url));~~~~~~~~~~~
   tsconfig.json:6:12: note: The target environment was set to "es2019" here
        6 │     "target": "es2019",
          ╵               ~~~~~~~~

  ✔ done
✨  Done in 2.01s.
Run error
╰─$ node build
node:internal/process/esm_loader:74
    internalBinding('errors').triggerUncaughtException(
                              ^

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
    at new NodeError (node:internal/errors:363:5)
    at createRequire (node:internal/modules/cjs/loader:1203:11)
    at file:///Users/seth.corker/projects/mfe-example/blog/build/index.js:1566:18
    at ModuleJob.run (node:internal/modules/esm/module_job:175:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5) {
  code: 'ERR_INVALID_ARG_VALUE'
}

To Reproduce

  1. Create a new sveltekit project with the skeleton template
  2. Add @sveltejs/adapter-node as a dev dependency
  3. Update svelte.config.js to use the adapter
  4. npm run build
  5. node build

Expected behavior
The server runs as expected when using node build

Stacktraces

Stack trace
node:internal/process/esm_loader:74
    internalBinding('errors').triggerUncaughtException(
                              ^

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
    at new NodeError (node:internal/errors:363:5)
    at createRequire (node:internal/modules/cjs/loader:1203:11)
    at file:///Users/seth.corker/projects/mfe-example/blog/build/index.js:1566:18
    at ModuleJob.run (node:internal/modules/esm/module_job:175:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5) {
  code: 'ERR_INVALID_ARG_VALUE'
}

Information about your SvelteKit Installation:

Diagnostics
  System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.07 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.3.0 - ~/.nvm/versions/node/v16.3.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 7.15.1 - ~/.nvm/versions/node/v16.3.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 91.0.4472.101
    Firefox: 86.0.1
    Firefox Developer Edition: 77.0
    Safari: 14.1.1
  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.25 
    @sveltejs/kit: next => 1.0.0-next.114 
    svelte: ^3.34.0 => 3.38.2

Severity
I found a workaround:

Update the tsconfig.json and change the target to match the target version specified in@sveltejs/adapter-node. I suspect es2020 should be used for SvelteKit and the adapter to work together as expected.

//tsconfig.json
{
    "compilerOptions": {
-        "target": "es2019"
+        "target": "es2020"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions