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

Reason: Unexpected identifier 'Promise' error on fresh Sveltekit project #481

Closed
MathiasWP opened this issue Jan 27, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@MathiasWP
Copy link

MathiasWP commented Jan 27, 2024

Version: Latest
Project type: Svelte(kit)
Language: TypeScript
Package manager: pnpm

Running knip on a Svelte project throws the following error message:

Error loading /Users/user/knip-test/vite.config.ts
Reason: Unexpected identifier 'Promise'
 ELIFECYCLE  Command failed with exit code 2.

I've created a minimal repro here: https://github.com/MathiasWP/knip-sveltekit-bug-repro

@MathiasWP MathiasWP added the bug Something isn't working label Jan 27, 2024
@MathiasWP MathiasWP changed the title Reason: Unexpected identifier 'Promise' error on Svelte project Reason: Unexpected identifier 'Promise' error on fresh Sveltekit project Jan 28, 2024
@webpro
Copy link
Collaborator

webpro commented Jan 29, 2024

This is a known issue, please see https://knip.dev/reference/known-issues

Track #194, #336, #346

@webpro webpro closed this as completed Jan 29, 2024
@webpro
Copy link
Collaborator

webpro commented Mar 14, 2024

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

@MathiasWP
Copy link
Author

bunx --bun knip

Using this resulted in the following error:

Computer app ‹main› » bunx --bun knip                                                                                                                                                                                                                                                                                                  1 ↵
[0.05ms] ".env.development"
1 | (function (process,nextTickQueue,drainMicrotasksFn,reportUncaughtExceptionFn){"use strict";var queue,process,nextTickQueue=nextTickQueue,drainMicrotasks=drainMicrotasksFn,reportUncaughtException=reportUncaughtExceptionFn;function validateFunction(cb){if(typeof cb!=="function"){const err=@makeTypeError(`The "callback" argument must be of type "function". Received type ${typeof cb}`);throw err.code="ERR_INVALID_ARG_TYPE",err}}var setup=()=>{queue=function createQueue(){class FixedCircularBuffer{constructor(){this.bottom=0,this.top=0,this.list=@newArrayWithSize(2048),this.next=null}isEmpty(){return this.top===this.bottom}isFull(){return(this.top+1&2047)===this.bottom}push(data){this.list[this.top]=data,this.top=this.top+1&2047}shift(){var{list,bottom}=this;const nextItem=list[bottom];if(nextItem===@undefined)return null;return list[bottom]=@undefined,this.bottom=bottom+1&2047,nextItem}}class FixedQueue{constructor(){this.head=this.tail=new FixedCircularBuffer}isEmpty(){return this.head.isEmpty()}push(data){if(this.head.isFull())this.head=this.head.next=new FixedCircularBuffer;this.head.push(data)}shift(){const tail=this.tail,next=tail.shift();if(tail.isEmpty()&&tail.next!==null)this.tail=tail.next,tail.next=null;return next}}return new FixedQueue}();function processTicksAndRejections(){var tock;do{while((tock=queue.shift())!==null){var{callback,args,frame}=tock,restore=@getInternalField(@asyncContext,0);@putInternalField(@asyncContext,0,frame);try{if(args===@undefined)callback();else switch(args.length){case 1:callback(args[0]);break;case 2:callback(args[0],args[1]);break;case 3:callback(args[0],args[1],args[2]);break;case 4:callback(args[0],args[1],args[2],args[3]);break;default:callback(...args);break}}catch(e){reportUncaughtException(e)}finally{@putInternalField(@asyncContext,0,restore)}}drainMicrotasks()}while(!queue.isEmpty())}@putInternalField(nextTickQueue,0,0),@putInternalField(nextTickQueue,1,queue),@putInternalField(nextTickQueue,2,processTicksAndRejections),setup=@undefined};function nextTick(cb,args){if(validateFunction(cb),setup)setup(),process=globalThis.process;if(process._exiting)return;queue.push({callback:cb,args:@argumentCount()>1?@Array.prototype.slice.@call(arguments,1):@undefined,frame:@getInternalField(@asyncContext,0)}),@putInternalField(nextTickQueue,0,1)}return nextTick})
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ^
SyntaxError: Import named 'parseArgs' not found in module 'util'.
      at processTicksAndRejections (:1:2602)
error: "knip" exited with code 1 (SIGHUP)

@webpro
Copy link
Collaborator

webpro commented Mar 14, 2024

You might be on a version of Bun that doesn't have parseArgs yet, not sure when exactly they introduced. Please try the latest?

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