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

Error importing pure TS packages (with Bun, Turbo, or neither) #74252

Open
ctjlewis opened this issue Dec 23, 2024 · 2 comments
Open

Error importing pure TS packages (with Bun, Turbo, or neither) #74252

ctjlewis opened this issue Dec 23, 2024 · 2 comments
Labels
bug Issue was opened via the bug report template. Module Resolution Module resolution (CJS / ESM, module resolving). Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js. TypeScript Related to types with Next.js. Webpack Related to Webpack with Next.js.

Comments

@ctjlewis
Copy link
Contributor

ctjlewis commented Dec 23, 2024

Link to the code that reproduces this issue

https://github.com/ctjlewis/ts-package-example

To Reproduce

Repro here:

https://github.com/ctjlewis/nextjs-ts-package

It attempts to load this simple mock package:

https://github.com/ctjlewis/ts-package-example


Without Bun, Turbo throws:

 ⨯ ./node_modules/ts-package-example/index.ts
Module parse failed: Unexpected token (1:7)
> export type GoodNextjsSupport = false;
| export type PossibleSupport = boolean;
| 

Import trace for requested module:
./node_modules/ts-package-example/index.ts
./app/page.tsx

When Bun is used with Turbo (bun --bun next dev --turbo), we get a segfault from Bun:

Bun v1.1.41 ([`b8f28ed`](<https://github.com/oven-sh/bun/tree/b8f28ed8afd1c2b60568b2b0158d39a674178027>)) on macos aarch64 [AutoCommand]

Segmentation fault at address 0x4000000002B

- *10 unknown/js code*

<!-- from bun.report: etViGWlalFX_NMfe5SXL -->

<sub>Sentry Issue: <strong><a href="https://bun-p9.sentry.io/issues/5298323857/">BUN-85</a></strong></sub>

Current vs. Expected behavior

It's important that the module resolve and load correctly. It is effectively the simplest possible pure-TS program.

Is it maybe the module export? I will try with exports keyword after this, but either way module entrypoint is simplest config.

I doubt it is, since it seems to throw on the type keyword - is it actually expecting JS from all node_modules?

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 21.0.0
  npm: 10.2.0
  Yarn: 1.22.19
  pnpm: 9.7.1
Relevant Packages:
  next: 15.1.1-canary.17 // Latest available version is detected (15.1.1-canary.17).
  eslint-config-next: 15.1.2
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Module Resolution, Runtime, Turbopack, TypeScript, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

cc @/Jarred-Sumner for Bun crash, cc @/jaredpalmer for Turbopack, cc @/leerob for coordination.

(Config issue: Tags removed.)

@ctjlewis ctjlewis added the bug Issue was opened via the bug report template. label Dec 23, 2024
@github-actions github-actions bot added Module Resolution Module resolution (CJS / ESM, module resolving). Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js. TypeScript Related to types with Next.js. Webpack Related to Webpack with Next.js. labels Dec 23, 2024
@ctjlewis
Copy link
Contributor Author

ctjlewis commented Dec 23, 2024

Ah, it wants us to manually specify packages to be transpiled, it does expect them all to be JS.

Why would I want my runtime import to throw because it contains TS? The simplest adjustment here is to handle this error specifically, and say, "Add { transpilePackages: ["your-package-here"] } to next.config.ts to transpile this package."

Never knew about this. I would print that message if there's ever any kind of parsing error and the import source ends in .ts or contains a type or interface keyword.

@ctjlewis
Copy link
Contributor Author

This does not fix the issue completely, since now we get a runtime error even though the module resolves and parses:

#73662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Module Resolution Module resolution (CJS / ESM, module resolving). Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js. TypeScript Related to types with Next.js. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant