forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warn and telemetry for customized esmExternals (vercel#67339)
### What * Warn with next.js when users customized `experimental.esmExternals` value * Add telemetry tracking on the customization usage for that flag. 0 for no customization, 1 for used non-default customized value ### Why `esmExternals` ideally can just remain as default value `true` which Next.js can handle the customization properly. Since next.js app router also supports it on canary now we're adding a warning to users that don't modify `esmExternals` option as it could affect module resolution on ESM packages.
- Loading branch information
Showing
8 changed files
with
94 additions
and
0 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
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
7 changes: 7 additions & 0 deletions
7
test/e2e/next-config-warnings/esm-externals-false/app/layout.js
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,7 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/next-config-warnings/esm-externals-false/app/page.js
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,3 @@ | ||
export default function Page() { | ||
return <div>Page</div> | ||
} |
36 changes: 36 additions & 0 deletions
36
test/e2e/next-config-warnings/esm-externals-false/esm-externals-false.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { findAllTelemetryEvents } from 'next-test-utils' | ||
|
||
// Turbopack hasn't fully enabled this option yet | ||
;(process.env.TURBOPACK ? describe.skip : describe)( | ||
'next-config-warnings - esm-externals-false', | ||
() => { | ||
const { next, isNextStart } = nextTestSetup({ | ||
files: __dirname, | ||
env: { | ||
NEXT_TELEMETRY_DEBUG: '1', | ||
}, | ||
}) | ||
|
||
it('should warn when using ESM externals: false', async () => { | ||
await next.fetch('/') | ||
|
||
expect(next.cliOutput).toContain( | ||
`The "experimental.esmExternals" option has been modified. experimental.esmExternals is not recommended to be modified as it may disrupt module resolution. Please update your next.config.js` | ||
) | ||
}) | ||
|
||
if (isNextStart) { | ||
it('should contain esmExternals feature usage in telemetry', async () => { | ||
const featureUsageEvents = findAllTelemetryEvents( | ||
next.cliOutput, | ||
'NEXT_BUILD_FEATURE_USAGE' | ||
) | ||
expect(featureUsageEvents).toContainEqual({ | ||
featureName: 'esmExternals', | ||
invocationCount: 1, | ||
}) | ||
}) | ||
} | ||
} | ||
) |
8 changes: 8 additions & 0 deletions
8
test/e2e/next-config-warnings/esm-externals-false/next.config.js
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,8 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
module.exports = { | ||
experimental: { | ||
esmExternals: false, | ||
}, | ||
} |