jspm / generator

JSPM Import Map Generator
Apache License 2.0
160 stars 20 forks source link

timeout is not appropriate #313

Open Bisstocuz opened 11 months ago

Bisstocuz commented 11 months ago

I'm using vite-plugin-jspm to build app.

tracemap/resolve: ./eq.js https://unpkg.com/lodash-es@4.17.21/_assocIndexOf.js -> https://unpkg.com/lodash-es@4.17.21/eq.js (URL resolution)
tracemap/resolve: ./eq.js https://unpkg.com/lodash-es@4.17.21/_assocIndexOf.js -> https://unpkg.com/lodash-es@4.17.21/eq.js (URL resolution)
tracemap/resolve: ./eq.js https://unpkg.com/lodash-es@4.17.21/_assocIndexOf.js -> https://unpkg.com/lodash-es@4.17.21/eq.js (URL resolution)
tracemap/resolve: @vue/shared https://unpkg.com/element-plus@2.3.8/es/components/space/src/use-space.mjs -> https://unpkg.com/@vue/shared@3.3.4/dist/shared.esm-bundler.js (installation resolution)
tracemap/resolve: @vue/reactivity https://unpkg.com/element-plus@2.3.8/es/hooks/use-lockscreen/index.mjs -> https://unpkg.com/@vue/reactivity@3.3.4/dist/reactivity.esm-bundler.js (installation resolution)
tracemap/resolve: @vue/shared https://unpkg.com/element-plus@2.3.8/es/components/message/src/method.mjs -> https://unpkg.com/@vue/shared@3.3.4/dist/shared.esm-bundler.js (installation resolution)
/app/node_modules/.pnpm/registry.npmmirror.com+minipass-fetch@1.4.1/node_modules/minipass-fetch/lib/index.js:110
      reject(new FetchError(`request to ${request.url} failed, reason: ${
             ^

FetchError: request to https://unpkg.com/element-plus@2.3.8/es/components/drawer/index.mjs failed, reason: Socket timeout
    at ClientRequest.<anonymous> (/app/node_modules/.pnpm/registry.npmmirror.com+minipass-fetch@1.4.1/node_modules/minipass-fetch/lib/index.js:110:14)
    at ClientRequest.emit (node:events:514:28)
    at TLSSocket.socketErrorListener (node:_http_client:501:9)
    at TLSSocket.emit (node:events:526:35)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at listOnTimeout (node:internal/timers:538:9)
    at process.processTimers (node:internal/timers:512:7) {
  code: 'ERR_SOCKET_TIMEOUT',
  timeout: 4000,
  errno: 'ERR_SOCKET_TIMEOUT',
  type: 'system'
}

Node.js v18.17.0
 ELIFECYCLE  Command failed with exit code 1.
ERROR: "build-prod" exited with 1.
 ELIFECYCLE  Command failed with exit code 1.

I tried visit https://unpkg.com/element-plus@2.3.8/es/components/drawer/index.mjs later, it responses successfully after several seconds.

Is there any options to set timeout?

guybedford commented 11 months ago

Thanks for posting, the timeout is not currently configurable but can be configured through the fetch options for make-fetch-happen. This is called in https://github.com/jspm/generator/blob/main/src/common/fetch-node.ts and the timeout docs can be found at https://github.com/npm/make-fetch-happen#--optsretry.

It should be straightforward to wire through an option, or simply extend the default - would you be able to try making a PR for that? If not I can make the update this week as well.

Bisstocuz commented 10 months ago

Thanks for posting, the timeout is not currently configurable but can be configured through the fetch options for make-fetch-happen. This is called in https://github.com/jspm/generator/blob/main/src/common/fetch-node.ts and the timeout docs can be found at https://github.com/npm/make-fetch-happen#--optsretry.

It should be straightforward to wire through an option, or simply extend the default - would you be able to try making a PR for that? If not I can make the update this week as well.

I guess my implement is still buggy, because I use vite-plugin-jspm with options:

export default defineConfig(({ mode }) => {
    return {
        plugins: [
            vue(),
            vueJsx(),
            jspmPlugin({
                fetchOptions: {
                    timeout: 10000,
                    maxSockets: 4,
                },
                defaultProvider: 'unpkg',
                debug: true
            }),
        ],

Then still received:

C:\Users\test\Documents\MBDownload\frontend\node_modules\.pnpm\registry.npmmirror.com+minipass-fetch@1.4.1\node_modules\minipass-fetch\lib\index.js:110
      reject(new FetchError(`request to ${request.url} failed, reason: ${
             ^

FetchError: request to https://unpkg.com/element-plus@2.3.9/theme-chalk/el-message.css failed, reason: Socket timeout
    at ClientRequest.<anonymous> (C:\Users\test\Documents\project\frontend\node_modules\.pnpm\registry.npmmirror.com+minipass-fetch@1.4.1\node_modules\minipass-fetch\lib\index.js:110:14)
    at ClientRequest.emit (node:events:513:28)
    at TLSSocket.socketErrorListener (node:_http_client:502:9)
    at TLSSocket.emit (node:events:525:35)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_SOCKET_TIMEOUT',
  timeout: 4000,
  errno: 'ERR_SOCKET_TIMEOUT',
  type: 'system'
}

Node.js v18.15.0
 ELIFECYCLE  Command failed with exit code 1.
ERROR: "build-prod" exited with 1.
 ELIFECYCLE  Command failed with exit code 1.

Could you please help review the whole function calling chain? I am not talented at JavaScript.

guybedford commented 10 months ago

@Bisstocuz ahh, looking at the stack more carefully we don't actually use minipass-fetch so that is likely used specifically in the Vite plugin or Vite fetch implementation.

Bisstocuz commented 10 months ago

@Bisstocuz ahh, looking at the stack more carefully we don't actually use minipass-fetch so that is likely used specifically in the Vite plugin or Vite fetch implementation.

@JayaKrishnaNamburu Hey do you have any ideas about this issue?

JayaKrishnaNamburu commented 10 months ago

@Bisstocuz can you try using the latest vite-plugin-jspm@0.5.1. It uses the latest @jspm/generator@1.1.10 which supports fetchOptions

https://www.npmjs.com/package/vite-plugin-jspm?activeTab=code https://github.com/jspm/generator/releases/tag/1.1.10

Bisstocuz commented 10 months ago

@Bisstocuz can you try using the latest vite-plugin-jspm@0.5.1. It uses the latest @jspm/generator@1.1.10 which supports fetchOptions

https://www.npmjs.com/package/vite-plugin-jspm?activeTab=code https://github.com/jspm/generator/releases/tag/1.1.10

I don't know why it reported:

 ERR_PNPM_NO_MATCHING_VERSION  No matching version found for vite-plugin-jspm@0.5.1

This error happened while installing a direct dependency of C:\Users\test\Documents\MBDownload\frontend

The latest release of vite-plugin-jspm is "0.5.0".

If you need the full list of all 8 published versions run "$ pnpm view vite-plugin-jspm versions".
JayaKrishnaNamburu commented 10 months ago

That's a bit weird, given it is already available in npm 🤔

JayaKrishnaNamburu commented 10 months ago

Any updates on this @Bisstocuz, were you able to make it work

Bisstocuz commented 10 months ago

Any updates on this @Bisstocuz, were you able to make it work

Still error, I am planned to check this issue several days later.