@@ -179,7 +179,6 @@ export async function optimizeDeps(
179
179
plugins : [
180
180
aliasPlugin ( { entries : config . alias } ) ,
181
181
depAssetExternalPlugin ( config ) ,
182
- // TODO user pre plugins?
183
182
resolvePlugin ( {
184
183
root : config . root ,
185
184
dedupe : config . dedupe ,
@@ -190,7 +189,6 @@ export async function optimizeDeps(
190
189
preferConst : true ,
191
190
namedExports : true
192
191
} ) ,
193
- // TODO user normal/post plugins?
194
192
commonjsPlugin ( {
195
193
include : [ / n o d e _ m o d u l e s / ] ,
196
194
extensions : [ '.js' , '.cjs' ]
@@ -215,38 +213,27 @@ export async function optimizeDeps(
215
213
}
216
214
writeFile ( dataPath , JSON . stringify ( data , null , 2 ) )
217
215
} catch ( e ) {
218
- if ( asCommand ) {
219
- throw e
220
- } else {
221
- logger . error (
222
- chalk . red ( `\nDep optimization failed with error:\n${ e . message } ` )
216
+ delete e . watchFiles
217
+ logger . error ( chalk . red ( `\nDep optimization failed with error:` ) )
218
+ if ( e . code === 'PARSE_ERROR' ) {
219
+ e . message += `\n\n${ chalk . cyan (
220
+ path . relative ( root , e . loc . file )
221
+ ) } \n${ chalk . dim ( e . frame ) } `
222
+ } else if ( e . message . match ( 'Node built-in' ) ) {
223
+ e . message += chalk . yellow (
224
+ `\n\nTip:\nMake sure your "dependencies" only include packages that you\n` +
225
+ `intend to use in the browser. If it's a Node.js package, it\n` +
226
+ `should be in "devDependencies".\n\n` +
227
+ `If you do intend to use this dependency in the browser and the\n` +
228
+ `dependency does not actually use these Node built-ins in the\n` +
229
+ `browser, you can add the dependency (not the built-in) to the\n` +
230
+ `"optimizeDeps.allowNodeBuiltins" option in vite.config.js.\n\n` +
231
+ `If that results in a runtime error, then unfortunately the\n` +
232
+ `package is not distributed in a web-friendly format. You should\n` +
233
+ `open an issue in its repo, or look for a modern alternative.`
223
234
)
224
- if ( e . code === 'PARSE_ERROR' ) {
225
- logger . error (
226
- chalk . cyan ( path . relative ( root , e . loc . file ) ) +
227
- `\n` +
228
- chalk . dim ( e . frame )
229
- )
230
- } else if ( e . message . match ( 'Node built-in' ) ) {
231
- logger . warn (
232
- chalk . yellow (
233
- `Tip:\nMake sure your "dependencies" only include packages that you\n` +
234
- `intend to use in the browser. If it's a Node.js package, it\n` +
235
- `should be in "devDependencies".\n\n` +
236
- `If you do intend to use this dependency in the browser and the\n` +
237
- `dependency does not actually use these Node built-ins in the\n` +
238
- `browser, you can add the dependency (not the built-in) to the\n` +
239
- `"optimizeDeps.allowNodeBuiltins" option in vite.config.js.\n\n` +
240
- `If that results in a runtime error, then unfortunately the\n` +
241
- `package is not distributed in a web-friendly format. You should\n` +
242
- `open an issue in its repo, or look for a modern alternative.`
243
- )
244
- // TODO link to docs once we have it
245
- )
246
- } else {
247
- throw e
248
- }
249
235
}
236
+ throw e
250
237
}
251
238
}
252
239
0 commit comments