jspm / project

Roadmap and management repo for the jspm project
159 stars 8 forks source link

Generator crashes when installing openai #335

Closed haikyuu closed 1 month ago

haikyuu commented 2 months ago

This is the error I get when trying to install openai.

file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:1566
            if (url.startsWith(pkgUrl)) {
                    ^

TypeError: Cannot read properties of null (reading 'startsWith')
    at Resolver.finalizeResolve (file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:1566:21)
    at Resolver.resolveExport (file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:1716:50)
    at async TraceMap.resolve (file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:2946:59)
    at async TraceMap.visit (file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:2728:26)
    at async Generator._install (file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:4005:13)
    at async Promise.all (index 0)
    at async Generator._install (file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/dist/generator-1fa589e1.js:3974:20)
    at async file:///Users/abdellah/workspace/home/desk/scrimba/jspm-gen/test/api/conflict.test.js:9:1

Node.js v20.11.1
Failed running '/Users/abdellah/workspace/home/desk/scrimba/jspm-gen/test/api/conflict.test.js'

I created a failing test here jspm/generator#356

guybedford commented 2 months ago

Thanks for sharing I've traced this down to https://github.com/openai/openai-node/pull/533 where an invalid usage of the "imports" field was added.

The root cause is actually the JSPM CDN itself generating the incorrect exports field when the imports field is invalid in this way. I will post a CDN fix soon.

This error should be an Unable to resolve error and that is correct, the error message not showing properly is the only generator bug.

In the mean time, you could also try loading from another CDN like esm.sh, as this is a CDN bug not a generator bug.

pvh commented 2 months ago

Just noting that I ran into this same bug -- I want to suggest @guybedford that the JSPM generator has a bug which is that it doesn't report "invalid imports field" or something but crashes without exposing the package name or the problem in a user-legible way.

guybedford commented 2 months ago

Thanks @pvh I did see that - posted the fix to the error message in https://github.com/jspm/generator/pull/358.

guybedford commented 1 month ago

OpenAI should now be working.