Skip to content

Commit 951ec02

Browse files
committed
fix(build): make relative imports in amd/cjs relative to the current module instead of the baseURI
1 parent 788a183 commit 951ec02

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/vite/src/node/build.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,13 @@ const relativeUrlMechanisms: Record<
13381338

13391339
const customRelativeUrlMechanisms = {
13401340
...relativeUrlMechanisms,
1341+
// override amd to use module.uri instead of document.baseURI
1342+
amd: (relativePath) => {
1343+
if (relativePath[0] !== '.') relativePath = './' + relativePath
1344+
return getResolveUrl(
1345+
`require.toUrl('${escapeId(relativePath)}'), ((typeof module !== 'undefined' && module?.id) ? require.toUrl(module.id) : document.baseURI)`,
1346+
)
1347+
},
13411348
'worker-iife': (relativePath) =>
13421349
getResolveUrl(
13431350
`'${escapeId(partialEncodeURIPath(relativePath))}', self.location.href`,

0 commit comments

Comments
 (0)