mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): correctly import node builtins in dev bundler (#2753)
This commit is contained in:
parent
2ba5f56374
commit
4b351504e8
@ -1,5 +1,6 @@
|
||||
import { pathToFileURL } from 'url'
|
||||
import { existsSync } from 'fs'
|
||||
import { builtinModules } from 'module'
|
||||
import { resolve } from 'pathe'
|
||||
import * as vite from 'vite'
|
||||
import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality'
|
||||
@ -73,8 +74,11 @@ async function transformRequest (opts: TransformOptions, id: string) {
|
||||
// Remove for externals
|
||||
const withoutVersionQuery = id.replace(/\?v=\w+$/, '')
|
||||
if (await isExternal(opts, withoutVersionQuery)) {
|
||||
const path = builtinModules.includes(withoutVersionQuery.split('node:').pop())
|
||||
? withoutVersionQuery
|
||||
: pathToFileURL(withoutVersionQuery)
|
||||
return {
|
||||
code: `(global, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) => import('${(pathToFileURL(withoutVersionQuery))}').then(r => { exports.default = r.default; ssrExportAll(r) }).catch(e => { console.error(e); throw new Error('[vite dev] Error loading external "${id}".') })`,
|
||||
code: `(global, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) => import('${path}').then(r => { exports.default = r.default; ssrExportAll(r) }).catch(e => { console.error(e); throw new Error('[vite dev] Error loading external "${id}".') })`,
|
||||
deps: [],
|
||||
dynamicDeps: []
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user