diff --git a/src/runtimes/node/bundlers/esbuild/bundler.ts b/src/runtimes/node/bundlers/esbuild/bundler.ts index 44e188501..9120499ab 100644 --- a/src/runtimes/node/bundlers/esbuild/bundler.ts +++ b/src/runtimes/node/bundlers/esbuild/bundler.ts @@ -207,6 +207,17 @@ var __glob = (map) => (path) => { const cleanTempFiles = getCleanupFunction([...bundlePaths.keys()]) const additionalPaths = includedFilesFromModuleDetection + const updatedWarnings = warnings.map((warning) => { + if (warning.id === 'empty-import-meta') { + return { + ...warning, + text: `"import.meta" is not available and will be empty, use __dirname instead`, + } + } + + return warning + }) + return { additionalPaths, bundlePaths, @@ -215,7 +226,7 @@ var __glob = (map) => (path) => { moduleFormat, nativeNodeModules, outputExtension, - warnings, + warnings: updatedWarnings, } } catch (error) { throw FunctionBundlingUserError.addCustomErrorInfo(error, { diff --git a/tests/fixtures/import-meta-warning/function.ts b/tests/fixtures/import-meta-warning/function.ts new file mode 100644 index 000000000..675466f98 --- /dev/null +++ b/tests/fixtures/import-meta-warning/function.ts @@ -0,0 +1,10 @@ +export const handler = async () => ({ + statusCode: 200, + body: JSON.stringify({ + msg: "Hello from .ts", + v: 2, + // @ts-ignore Error expected + importMetaURL: import.meta.url, + dirname: typeof __dirname === "undefined" ? undefined : __dirname, + }), +}); \ No newline at end of file diff --git a/tests/main.test.ts b/tests/main.test.ts index 87c095018..e8834fb48 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -2765,4 +2765,17 @@ describe('zip-it-and-ship-it', () => { expect(handler()).toBe(true) } }) + + testMany('esbuild hides unactionable import.meta warning', ['bundler_esbuild'], async (options) => { + const { + files: [{ bundlerWarnings }], + } = await zipFixture('import-meta-warning', { + length: 1, + opts: options, + }) + expect(bundlerWarnings).toHaveLength(1) + expect((bundlerWarnings?.[0] as any).text).toEqual( + `"import.meta" is not available and will be empty, use __dirname instead`, + ) + }) })