bridge icon indicating copy to clipboard operation
bridge copied to clipboard

occur error when import "node:something"

Open kyumoon opened this issue 1 year ago • 1 comments

Environment

Reproduction

https://github.com/kyumoon/nuxt-birdge-example/tree/test/ofetch

Describe the bug

I am currently developing in a 'bridge + webpack' environment and found an error while trying to integrate ofetch in advance for migration. The error is the same as the issue reported https://github.com/nuxt/bridge/issues/1066. closed PR: https://github.com/unjs/ofetch/pull/433

From what I have identified, imports with the 'node:' prefix do not work properly and need to be removed for the 'webpack + bridge' environment to function correctly.

스크린샷 2024-08-28 오후 5 54 50

Additional context

No response

Logs

No response

kyumoon avatar Aug 28 '24 09:08 kyumoon

This may be a problem with Nuxt 2 rather than Nuxt Bridge. (as it also occurs without the nuxt bridge).

wattanx avatar Aug 28 '24 12:08 wattanx

I recently discovered that this issue can be avoided by using hooks like the following.

https://stackblitz.com/edit/github-at3kju91-mr1ksdbf

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  hooks: {
    'webpack:config': (configs) => {
      for (const config of configs) {
        if (Array.isArray(config.externals)) {
          config.externals.push('node:http')
          config.externals.push('node:https')
        }
      }
    }
  }
})

wattanx avatar Mar 23 '25 02:03 wattanx