Skip to content
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

feat: relax dep browser externals as warning #9837

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ module.exports = Object.create(new Proxy({}, {
key !== 'constructor' &&
key !== 'splice'
) {
throw new Error(\`Module "${path}" has been externalized for browser compatibility. Cannot access "${path}.\${key}" in client code.\`)
console.warn(\`Module "${path}" has been externalized for browser compatibility. Cannot access "${path}.\${key}" in client code.\`)
}
}
}))`
Expand Down
23 changes: 13 additions & 10 deletions playground/optimize-deps/__tests__/optimize-deps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,23 @@ test('flatten id should generate correctly', async () => {
test.runIf(isServe)('error on builtin modules usage', () => {
expect(browserLogs).toEqual(
expect.arrayContaining([
// from dep-with-builtin-module-esm top-level try-catch
// from dep-with-builtin-module-esm
expect.stringMatching(/dep-with-builtin-module-esm.*is not a function/),
// dep-with-builtin-module-esm warnings
expect.stringContaining(
'dep-with-builtin-module-esm Error: Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFileSync" in client code.'
'Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFileSync" in client code.'
),
expect.stringContaining(
'dep-with-builtin-module-esm Error: Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code.'
'Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code.'
),
// from dep-with-builtin-module-cjs top-level try-catch
// from dep-with-builtin-module-cjs
expect.stringMatching(/dep-with-builtin-module-cjs.*is not a function/),
// dep-with-builtin-module-cjs warnings
expect.stringContaining(
'dep-with-builtin-module-cjs Error: Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code.'
'Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFileSync" in client code.'
),
expect.stringContaining(
'Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code.'
)
])
)
Expand All @@ -167,11 +174,7 @@ test.runIf(isServe)('error on builtin modules usage', () => {
expect.arrayContaining([
// from user source code
'Module "buffer" has been externalized for browser compatibility. Cannot access "buffer.Buffer" in client code.',
'Module "child_process" has been externalized for browser compatibility. Cannot access "child_process.execSync" in client code.',
// from dep-with-builtin-module-esm read()
'Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFileSync" in client code.',
// from dep-with-builtin-module-esm read()
'Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFileSync" in client code.'
'Module "child_process" has been externalized for browser compatibility. Cannot access "child_process.execSync" in client code.'
])
)
})