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

Typescript #45

Open
2 tasks done
azinazadi opened this issue Jun 14, 2024 · 0 comments
Open
2 tasks done

Typescript #45

azinazadi opened this issue Jun 14, 2024 · 0 comments

Comments

@azinazadi
Copy link

azinazadi commented Jun 14, 2024

Double-Check

Kitbook version

1.0.0-beta.31

Describe the bug

We use Kitbook in our Sveltekit based EShop and we are very happy about it, it is such a powerful and useful tool and became a vital part of our stack. Last week we realized that our staging server does not load the Kitbook giving a 500. It loads but perfectly on our local machines.

This is the error:

This file is being treated as an ES module because it has a '.js' file extension and '/Users/azin/dev/kitbook/packages/kitbook/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at isFileSystemCaseSensitive (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:6475:43)
    at getNodeSystem (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:6263:48)
    at file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:6684:20
    at src/compiler/sys.ts (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:6690:11)
    at __init (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:116:60)
    at src/compiler/_namespaces/ts.ts (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:130179:9)
    at __init (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:116:60)
    at src/typescript/_namespaces/ts.ts (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:190571:9)
    at __init (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:116:60)
    at src/typescript/typescript.ts (file:///Users/azin/dev/kitbook/packages/kitbook/build/server/chunks/Tools.svelte_svelte_type_style_lang-qhah-Kye.js:190582:9)

After digging deep into the problem I found out that it comes out to importing typescript in CodeMirror.svelte

  import ts, { type CompilerOptions } from 'typescript'

Now, this works fine when we run the server using vite preview command. The problem only appears when we use the node adapter in svelte.config.js and then start the server with node build command.

Reproduction

I made a repo that shows the problem.

Clone the repo:

https://github.com/azinazadi/kitbook-ts-issue.git

In this repo I made these changes:

  1. Use adapter-node in svelte.config.js

  2. I removed everything extra from CodeMirror.svelte and just left the import there, to create a minimum failing example.

Build it:

# Navigate to the 'kitbook' package directory
cd packages/kitbook

# Install all required dependencies using pnpm
pnpm install

# Build the project
pnpm build

Run the node server

node build

Now when you open the localhose:3000, you will see the 500 error.

System Info

I run on Mac OS M3, Sonoma 14.3
Node 20.14.0
pnpm 9.1.0

Why is this happenig?

As I understood it when you run the server using vite preview, the vite server handles the imports better and takes better care of modules. The Node server apparently does a more basic job which leads to this problem.

azinazadi pushed a commit to azinazadi/kitbook-ts-issue that referenced this issue Jun 14, 2024
azinazadi pushed a commit to azinazadi/kitbook-ts-issue that referenced this issue Jun 14, 2024
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