New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: modify type
field of transpiled ESM packages
#783
Conversation
// "/my-transpiled-function.js" => "/my-function.js" | ||
// | ||
// When "/my-transpiled-function.js" is found in the list of files, it will | ||
// be added to the archive with the "/my-function.js" path. | ||
aliases?: Map<string, string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aliases
existed before, I've just added a comment to clarify what it's for.
// When "/my-function.js" is found in the list of files, it will be added to | ||
// the archive with "console.log(`Hello!`)" as its source, replacing whatever | ||
// the file at "/my-function.js" contains. | ||
rewrites?: Map<string, string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewrites
is a new concept.
const { fileList: dependencyPaths } = await nodeFileTrace([mainFile], { | ||
const { | ||
fileList: dependencyPaths, | ||
esmFileList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were previously relying on NFT's cache object to inspect which of the paths corresponded to ESM files, but I realised there's a esmFileList
property that contains just that, so there's no need to muck about with the internal cache.
// The version of ECMAScript to use as the build target. This will determine | ||
// whether certain features are transpiled down or left untransformed. | ||
const nodeTarget = getBundlerTarget(config.nodeVersion) | ||
|
||
await build({ | ||
const transpiled = await build({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were piping the output of esbuild to a temporary file, but actually we can just get the result loaded into memory by setting write: false
and avoid creating a file altogether.
|
||
addZipFile(archive, srcFile, normalizedFilename, stat) | ||
if (rewrites.has(srcFile)) { | ||
addZipContent(archive, rewrites.get(srcFile) as string, normalizedDestPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of microsoft/TypeScript#13086.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Hey team, I believe this was supposed to be related with this thread: https://answers.netlify.com/t/nextjs-page-with-server-side-logic-throws-error-cannot-find-module-os/46431/? Could someone confirm? Users are still reporting it's not working. |
- Summary
When transpiling ESM packages to CJS, we should also modify their
package.json
so that thetype
field is set tocommonjs
, notmodule
.- Test plan
Existing tests reused.
- A picture of a cute animal (not mandatory but encouraged)