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

Unexpected package.json with "type": "commonjs" break nextjs 14 complie #956

Closed
aidenlx opened this issue May 18, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@aidenlx
Copy link

aidenlx commented May 18, 2024

Report a bug

importing ArkType will trigger the following error in nextjs 14:

 ⨯ ./node_modules/.pnpm/arktype@2.0.0-dev.13/node_modules/arktype/out/api.js
Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
> export { ArkError as ArkError, ArkErrors } from "@arktype/schema";
| export { ambient, ark, declare, define, match, type } from "./ark.js";
| export { Module } from "./module.js";

Import trace for requested module:
./node_modules/.pnpm/arktype@2.0.0-dev.13/node_modules/arktype/out/api.js
./app/page.tsx

🧩 Context

  • ArkType version: 2.0.0-dev.13
  • TypeScript version (5.1+): 5.4.5
  • Other context you think may be relevant (JS flavor, OS, etc.):
    • nextjs 14.2.3

🧑‍💻 Repro

https://github.com/aidenlx/arktype-repro

It's likely due to package.json with only "type": "commonjs" in out directory. manually deleting them from the following solve the issue:

  • node_modules/arktype/out/
  • node_modules/@arktype/schema/out/
  • node_modules/@arktype/util/out/
@aidenlx aidenlx added the bug Something isn't working label May 18, 2024
@ssalbdivad
Copy link
Member

Ahh okay I think I figured out what happened!

As of now, I don't plan to support CJS at all in the main package in 2.0, but I shipped this version from my local env where I had recently built a custom CJS version of the package for https://github.com/moltar/typescript-runtime-type-benchmarks.

Even though I rebuilt after that, I likely reused the same out folder without an rm -rf before rebuilding so the package.json just stuck around 🤦

I will add an rm -rf to my build script to avoid this happening again and will likely release 2.0.0-dev.14 today or tomorrow.

@ciscoheat
Copy link

This just happened to me as well when building a SvelteKit project. It works when developing, but the build command fails. Great that a fix is around the corner. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done (merged or closed)
Development

No branches or pull requests

3 participants