mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
fix(ssr): avoid using tryNodeResolve
on absolute paths (#6488)
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
This commit is contained in:
parent
b2d972e53b
commit
f346d89741
@ -17,6 +17,7 @@
|
||||
"only-object-assigned-exports": "file:./only-object-assigned-exports",
|
||||
"primitive-export": "file:./primitive-export",
|
||||
"read-file-content": "file:./read-file-content",
|
||||
"require-absolute": "file:./require-absolute",
|
||||
"ts-transpiled-exports": "file:./ts-transpiled-exports"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
1
packages/playground/ssr-deps/require-absolute/foo.js
Normal file
1
packages/playground/ssr-deps/require-absolute/foo.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports.hello = 'Hello World!'
|
3
packages/playground/ssr-deps/require-absolute/index.js
Normal file
3
packages/playground/ssr-deps/require-absolute/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports.hello = () => require(path.resolve(__dirname, './foo.js')).hello
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "require-absolute",
|
||||
"version": "0.0.0",
|
||||
"private": true
|
||||
}
|
@ -8,6 +8,7 @@ import bcrypt from 'bcrypt'
|
||||
import definePropertiesExports from 'define-properties-exports'
|
||||
import definePropertyExports from 'define-property-exports'
|
||||
import onlyObjectAssignedExports from 'only-object-assigned-exports'
|
||||
import requireAbsolute from 'require-absolute'
|
||||
|
||||
export async function render(url, rootDir) {
|
||||
let html = ''
|
||||
@ -41,5 +42,8 @@ export async function render(url, rootDir) {
|
||||
const onlyObjectAssignedExportsMessage = onlyObjectAssignedExports.hello()
|
||||
html += `\n<p class="only-object-assigned-exports-msg">message from only-object-assigned-exports: ${onlyObjectAssignedExportsMessage}</p>`
|
||||
|
||||
const requireAbsoluteMessage = requireAbsolute.hello()
|
||||
html += `\n<p class="require-absolute-msg">message from require-absolute: ${requireAbsoluteMessage}</p>`
|
||||
|
||||
return html + '\n'
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import path from 'path'
|
||||
import { pathToFileURL } from 'url'
|
||||
import type { ViteDevServer } from '../server'
|
||||
import {
|
||||
bareImportRE,
|
||||
dynamicImport,
|
||||
isBuiltin,
|
||||
unwrapId,
|
||||
@ -232,9 +233,9 @@ async function nodeImport(
|
||||
// When an ESM module imports an ESM dependency, this hook is *not* used.
|
||||
const unhookNodeResolve = hookNodeResolve(
|
||||
(nodeResolve) => (id, parent, isMain, options) => {
|
||||
// Fix #5709, use require to resolve files with the '.node' file extension.
|
||||
// See detail, https://nodejs.org/api/addons.html#addons_loading_addons_using_require
|
||||
if (id[0] === '.' || isBuiltin(id) || id.endsWith('.node')) {
|
||||
// Use the Vite resolver only for bare imports while skipping
|
||||
// any built-in modules and binary modules.
|
||||
if (!bareImportRE.test(id) || isBuiltin(id) || id.endsWith('.node')) {
|
||||
return nodeResolve(id, parent, isMain, options)
|
||||
}
|
||||
if (parent) {
|
||||
|
@ -463,6 +463,7 @@ importers:
|
||||
only-object-assigned-exports: file:./only-object-assigned-exports
|
||||
primitive-export: file:./primitive-export
|
||||
read-file-content: file:./read-file-content
|
||||
require-absolute: file:./require-absolute
|
||||
ts-transpiled-exports: file:./ts-transpiled-exports
|
||||
dependencies:
|
||||
bcrypt: 5.0.1
|
||||
@ -473,6 +474,7 @@ importers:
|
||||
only-object-assigned-exports: link:only-object-assigned-exports
|
||||
primitive-export: link:primitive-export
|
||||
read-file-content: link:read-file-content
|
||||
require-absolute: link:require-absolute
|
||||
ts-transpiled-exports: link:ts-transpiled-exports
|
||||
devDependencies:
|
||||
cross-env: 7.0.3
|
||||
@ -499,6 +501,9 @@ importers:
|
||||
packages/playground/ssr-deps/read-file-content:
|
||||
specifiers: {}
|
||||
|
||||
packages/playground/ssr-deps/require-absolute:
|
||||
specifiers: {}
|
||||
|
||||
packages/playground/ssr-deps/ts-transpiled-exports:
|
||||
specifiers: {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user