Skip to content

Unexpected early exit (code 13) when trying to import {} from a dynamic import() #1882

Description

@brianjenkins94

This is a weird one where I could just be doing something stupid, but I'm reasonably certain this is code that has worked for me in the past.

I've run into the exit code 13 problem before but it turned out to be a conditional logic issue where I wasn't returning anything.

For reference:

13 Unfinished Top-Level Await: await was used outside of a function in the top-level code, but the passed Promise never resolved.

https://nodejs.org/api/process.html#exit-codes

Search Terms

exit code 13, dynamic import

Expected Behavior

The BASE_URL gets console.logd.

Actual Behavior

Unexpected early exit (code 13) on the dynamic import().

Steps to reproduce the problem

node --experimental-specifier-resolution=node --loader=ts-node/esm server.ts

Minimal reproduction

// server.ts
import * as path from "path";
import * as url from "url";

const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export const BASE_URL = new URL("http://localhost:8080");

const exports = await import(url.pathToFileURL(path.join(__dirname, "index.ts")).toString());

console.log(exports); // <-- we never get here
// index.ts

// The error appears to be contingent on this import:
import { BASE_URL } from "./server";

export async function get(request, response) {
	console.log(BASE_URL);
}

Specifications

Windows (git-bash):

> npx ts-node -vvv
ts-node v10.9.1 C:\Users\User\Desktop\ts-node-repro\node_modules\ts-node
node v18.6.0
compiler v4.8.3 C:\Users\User\Desktop\ts-node-repro\node_modules\typescript\lib\typescript.js

Linux (devcontainer):

# npx ts-node -vvv
ts-node v10.9.1 /workspaces/prizmdoc-viewer-spreadsheet-look-and-feel/node_modules/ts-node
node v18.9.0
compiler v4.8.3 /workspaces/prizmdoc-viewer-spreadsheet-look-and-feel/node_modules/typescript/lib/typescript.js
  • tsconfig.json:
{
	"compilerOptions": {
		"allowJs": true,
		"allowSyntheticDefaultImports": true,
		"alwaysStrict": true,
		"esModuleInterop": true,
		//"exactOptionalPropertyTypes": true,
		"experimentalDecorators": true,
		"module": "ESNext",
		"moduleResolution": "Node",
		"noImplicitOverride": true,
		"noImplicitReturns": true,
		"noPropertyAccessFromIndexSignature": true,
		"target": "ES2022"
	}
}
  • package.json:
{
  "type": "module",
  "scripts": {
    "start": "node --experimental-specifier-resolution=node --loader=ts-node/esm server.ts"
  },
  "dependencies": {
    "@types/node": "latest",
    "ts-node": "latest",
    "typescript": "latest"
  }
}
  • Operating system and version:

I've tried on Windows (21H2) and Linux via a devcontainer (Linux docker-desktop 5.10.16.3-microsoft-standard-WSL2), same results.

Activity

  1. brianjenkins94 commented on Sep 11, 2022

    @brianjenkins94
    Author

    csspotcode helped me on Discord to determine that the same results happen without ts-node at all.

  2. locked and limited conversation to collaborators on Sep 11, 2022
  3. converted this issue into a discussion #1883 on Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions