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

[SvelteKit + TS] SyntaxError: Unexpected identifier 'Promise' #416

Closed
vojtechsimetka opened this issue Dec 29, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@vojtechsimetka
Copy link
Contributor

Knip@3 does not work with SvelteKit@2 with Typescript enabled. It works just with with JS only or in SvelteKit@1 and svelte@3.

Error output

Analyzing workspace ....
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
Error loading /Users/vojtechsimetka/Repos/testdemo/test/vite.config.ts
Reason: Unexpected identifier 'Promise'

How to reproduce

  1. Create new SvelteKit project and enable Typescript. You also need to build the project because .svelte-kit/tsconfig.json does not exist at this point.
pnpm create svelte@latest test && \
cd test && \
pnpm i && \
pnpm build
  1. Run knip
pnpx knip

Debug output

Click to expand
[*] Unresolved configuration (from CLI arguments)
{
  cwd: '/Users/testuser/test',
  tsConfigFile: undefined,
  gitignore: true,
  isProduction: false,
  isStrict: false,
  isShowProgress: false,
  isIncludeEntryExports: false,
  isIsolateWorkspaces: false,
  isFix: false,
  fixTypes: []
}
[*] Included workspaces
[ 'test' ]
[*] Included workspace configs
[
  {
    pkgName: 'test',
    name: '.',
    config: {
      entry: [
        '{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!',
        'src/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!'
      ],
      project: [ '**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!' ],
      paths: {},
      ignore: [],
      ignoreBinaries: [],
      ignoreDependencies: [],
      isIncludeEntryExports: false
    },
    ancestors: []
  }
]
[.] Enabled plugins (.)
[ 'Svelte', 'TypeScript', 'Vite' ]
[.] Definition paths (7)
[
  '/Users/testuser/test/.svelte-kit/ambient.d.ts',
  '/Users/testuser/test/.svelte-kit/non-ambient.d.ts',
  '/Users/testuser/test/.svelte-kit/types/src/routes/$types.d.ts',
  '/Users/testuser/test/.svelte-kit/types/src/routes/about/$types.d.ts',
  '/Users/testuser/test/.svelte-kit/types/src/routes/sverdle/$types.d.ts',
  '/Users/testuser/test/.svelte-kit/types/src/routes/sverdle/how-to-play/$types.d.ts',
  '/Users/testuser/test/src/app.d.ts'
]
[.] Entry paths in package.json (0)
[]
[.] Svelte config file paths (0)
[]
[.] Svelte dependencies (5)
[
  'entry:svelte.config.js',
  'entry:vite*.config.{js,mjs,ts,cjs,mts,cts}',
  'production:src/hooks.{server,client}.{js,ts}',
  'production:src/params/*{js,ts}',
  'production:src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}'
]
[.] TypeScript config file paths (1)
[ '/Users/testuser/test/tsconfig.json' ]
[.] TypeScript dependencies (0)
[]
[.] Vite config file paths (1)
[ '/Users/testuser/test/vite.config.ts' ]
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/util/loader.js:37
        throw new LoaderError(`Error loading ${filePath}`, { cause: error });
              ^

LoaderError: Error loading /Users/testuser/test/vite.config.ts
    at load (file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/util/loader.js:37:15)
    at Module.findViteDependencies (file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/plugins/vite/index.js:9:31)
    at WorkspaceWorker.findDependenciesByPlugins (file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/WorkspaceWorker.js:193:59)
    at async WorkspaceWorker.findAllDependencies (file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/WorkspaceWorker.js:219:9)
    at async main (file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/index.js:120:30)
    at async run (file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/cli.js:23:73)
    at async file:///Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/knip@3.9.0_@types+node@20.10.5_typescript@5.3.3/node_modules/knip/dist/cli.js:77:1 {
  [cause]: /Users/testuser/test/node_modules/.pnpm/@sveltejs+kit@2.0.6_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.8_vite@5.0.10/node_modules/@sveltejs/kit/src/core/sync/ts.js:5
    exports.ts = ts = (await Promise.resolve().then(() => require('typescript'))).default;
                             ^^^^^^^
  
  SyntaxError: Unexpected identifier 'Promise'
      at new Script (node:vm:99:7)
      at createScript (node:vm:247:10)
      at Object.runInThisContext (node:vm:295:10)
      at evalModule (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:256254)
      at jiti (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:254371)
      at /Users/testuser/test/node_modules/.pnpm/@sveltejs+kit@2.0.6_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.8_vite@5.0.10/node_modules/@sveltejs/kit/src/core/sync/write_types/index.js:6:11
      at evalModule (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:256443)
      at jiti (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:254371)
      at /Users/testuser/test/node_modules/.pnpm/@sveltejs+kit@2.0.6_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.8_vite@5.0.10/node_modules/@sveltejs/kit/src/core/sync/sync.js:6:15
      at evalModule (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:256443)
      at jiti (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:254371)
      at /Users/testuser/test/node_modules/.pnpm/@sveltejs+kit@2.0.6_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.8_vite@5.0.10/node_modules/@sveltejs/kit/src/exports/vite/index.js:10:36
      at evalModule (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:256443)
      at jiti (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:254371)
      at /Users/testuser/test/vite.config.ts:1:175
      at evalModule (/Users/testuser/Library/pnpm/store/v3/tmp/dlx-69205/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:256443)
}

Node.js v20.10.0
@vojtechsimetka vojtechsimetka added the bug Something isn't working label Dec 29, 2023
@vojtechsimetka
Copy link
Contributor Author

Closing as a duplicate of #346

@vojtechsimetka vojtechsimetka closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2023
@webpro
Copy link
Collaborator

webpro commented Jan 2, 2024

Fwiw, I've added the error message to https://knip.dev/reference/known-issues

@webpro
Copy link
Collaborator

webpro commented Mar 14, 2024

Knip v5.1 introduce a new workaround: bunx --bun knip

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
None yet
Development

No branches or pull requests

2 participants