Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

fix: compile away node:-namespaced imports #806

Merged
merged 8 commits into from
Nov 12, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Plugin } from '@netlify/esbuild'
const getNodeBuiltinPlugin = (): Plugin => ({
name: 'builtin-modules',
setup(build) {
build.onResolve({ filter: /^node:/ }, () => ({ external: true }))
build.onResolve({ filter: /^node:/ }, (args) => ({ path: args.path.slice('node:'.length), external: true }))
},
})

Expand Down
7 changes: 5 additions & 2 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2282,8 +2282,11 @@ testMany(
testMany(
'Handles built-in modules imported with the `node:` prefix',
['bundler_default', 'bundler_default_nft', 'bundler_nft', 'bundler_esbuild', 'bundler_esbuild_zisi'],
async (options, t) => {
await zipFixture(t, 'node-force-builtin-esm', {
async (options, t, bundler) => {
const nodePrefixIsUnderstood = semver.gte(nodeVersion, '14.18')
const nodePrefixIsCompiledAway = bundler.includes('esbuild')
const zip = nodePrefixIsCompiledAway || nodePrefixIsUnderstood ? zipNode : zipFixture
await zip(t, 'node-force-builtin-esm', {
opts: options,
})
},
Expand Down