-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make ESM output valid Node ESM (#10928)
Some bundlers, especially older ones, don't support resolving `.mjs` files out of the box. To retain compatibility with these bundlers without requiring users to adjust their configurations, we need to keep all our ESM output as `.js` files. So node.js loads these as modules, we output a `package.json` into each `./build/esm` output directory containing simply `{ "type": "module" }`. This works because whenever node.js is asked to load a `.js` file, it tries to work out whether this is CJS or ESM by searching up through parent directories until it finds a `package.json` with the `type` set. This PR: - Adds a Rollup plugin that injects the `package.json` into the ESM output - Adds the package `exports` that @AbhiPrasad worked out for #10833 - Fixes an import issue with `next/router` which is CJS (at least in v10) - Fixes an import issue with `@prisma/instrumentation` which is CJS - Ensures that CJS only integrations are not included in the `@sentry/node` default integrations when running as ESM This PR also makes some unrelated changes: - Changes to the old Node SDKs to allow the tests to pass - Removes the bundle size analysis CI job as it doesn't appears to be compatible with the node ESM output
- Loading branch information
Showing
44 changed files
with
373 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Outputs a package.json file with {type: module} in the root of the output directory so that Node | ||
* treats .js files as ESM. | ||
*/ | ||
export function makePackageNodeEsm() { | ||
return { | ||
name: 'make-package-node-esm', | ||
generateBundle() { | ||
this.emitFile({ | ||
type: 'asset', | ||
fileName: 'package.json', | ||
source: '{ "type": "module" }', | ||
}); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/nextjs/test/performance/pagesRouterInstrumentation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"include": ["src/**/*"], | ||
|
||
"compilerOptions": { | ||
"lib": ["es2017"] | ||
"lib": ["es2017"], | ||
"module": "Node16" | ||
} | ||
} |
Oops, something went wrong.