/
error.ts
905 lines (824 loc) · 28.2 KB
/
error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
import { locate } from 'locate-character';
import type Module from '../Module';
import type {
InternalModuleFormat,
NormalizedInputOptions,
RollupLog,
RollupWarning,
WarningHandler
} from '../rollup/types';
import getCodeFrame from './getCodeFrame';
import { printQuotedStringList } from './printStringList';
import relativeId from './relativeId';
export function error(base: Error | RollupLog): never {
if (!(base instanceof Error)) {
base = Object.assign(new Error(base.message), base);
Object.defineProperty(base, 'name', { value: 'RollupError' });
}
throw base;
}
export function augmentCodeLocation(
props: RollupLog,
pos: number | { column: number; line: number },
source: string,
id: string
): void {
if (typeof pos === 'object') {
const { line, column } = pos;
props.loc = { column, file: id, line };
} else {
props.pos = pos;
const { line, column } = locate(source, pos, { offsetLine: 1 });
props.loc = { column, file: id, line };
}
if (props.frame === undefined) {
const { line, column } = props.loc;
props.frame = getCodeFrame(source, line, column);
}
}
// Error codes should be sorted alphabetically while errors should be sorted by
// error code below
const ADDON_ERROR = 'ADDON_ERROR',
ALREADY_CLOSED = 'ALREADY_CLOSED',
AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES',
ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE',
ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED',
ASSET_NOT_FOUND = 'ASSET_NOT_FOUND',
ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET',
ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING',
BAD_LOADER = 'BAD_LOADER',
CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE',
CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK',
CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED',
CHUNK_INVALID = 'CHUNK_INVALID',
CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY',
CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT',
CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT',
DEPRECATED_FEATURE = 'DEPRECATED_FEATURE',
DUPLICATE_IMPORT_OPTIONS = 'DUPLICATE_IMPORT_OPTIONS',
DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME',
EMPTY_BUNDLE = 'EMPTY_BUNDLE',
EVAL = 'EVAL',
EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS',
FAIL_AFTER_WARNINGS = 'FAIL_AFTER_WARNINGS',
FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT',
FILE_NOT_FOUND = 'FILE_NOT_FOUND',
ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME',
ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT',
INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN',
INVALID_CHUNK = 'INVALID_CHUNK',
INVALID_CONFIG_MODULE_FORMAT = 'INVALID_CONFIG_MODULE_FORMAT',
INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION',
INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID',
INVALID_OPTION = 'INVALID_OPTION',
INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK',
INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE',
INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE',
INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT',
MISSING_CONFIG = 'MISSING_CONFIG',
MISSING_EXPORT = 'MISSING_EXPORT',
MISSING_EXTERNAL_CONFIG = 'MISSING_EXTERNAL_CONFIG',
MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME',
MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT',
MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT',
MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS',
MISSING_OPTION = 'MISSING_OPTION',
MIXED_EXPORTS = 'MIXED_EXPORTS',
MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE',
NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT',
NO_FS_IN_BROWSER = 'NO_FS_IN_BROWSER',
NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE',
ONLY_INLINE_SOURCEMAPS = 'ONLY_INLINE_SOURCEMAPS',
PARSE_ERROR = 'PARSE_ERROR',
PLUGIN_ERROR = 'PLUGIN_ERROR',
SHIMMED_EXPORT = 'SHIMMED_EXPORT',
SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN',
SOURCEMAP_ERROR = 'SOURCEMAP_ERROR',
SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT',
THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED',
UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT',
UNKNOWN_OPTION = 'UNKNOWN_OPTION',
UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY',
UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT',
UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT',
VALIDATION_ERROR = 'VALIDATION_ERROR';
export function errAddonNotGenerated(message: string, hook: string, plugin: string): RollupLog {
return {
code: ADDON_ERROR,
message: `Could not retrieve "${hook}". Check configuration of plugin "${plugin}".
\tError Message: ${message}`
};
}
export function errAlreadyClosed(): RollupLog {
return {
code: ALREADY_CLOSED,
message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
};
}
export function errAmbiguousExternalNamespaces(
binding: string,
reexportingModule: string,
usedModule: string,
sources: string[]
): RollupLog {
return {
binding,
code: AMBIGUOUS_EXTERNAL_NAMESPACES,
ids: sources,
message: `Ambiguous external namespace resolution: "${relativeId(
reexportingModule
)}" re-exports "${binding}" from one of the external modules ${printQuotedStringList(
sources.map(module => relativeId(module))
)}, guessing "${relativeId(usedModule)}".`,
reexporter: reexportingModule
};
}
export function errAnonymousPluginCache(): RollupLog {
return {
code: ANONYMOUS_PLUGIN_CACHE,
message:
'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
};
}
export function errAssetNotFinalisedForFileName(name: string): RollupLog {
return {
code: ASSET_NOT_FINALISED,
message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_<referenceId>, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.`
};
}
export function errAssetReferenceIdNotFoundForSetSource(assetReferenceId: string): RollupLog {
return {
code: ASSET_NOT_FOUND,
message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
};
}
export function errAssetSourceAlreadySet(name: string): RollupLog {
return {
code: ASSET_SOURCE_ALREADY_SET,
message: `Unable to set the source for asset "${name}", source already set.`
};
}
export function errNoAssetSourceSet(assetName: string): RollupLog {
return {
code: ASSET_SOURCE_MISSING,
message: `Plugin error creating asset "${assetName}" - no asset source set.`
};
}
export function errBadLoader(id: string): RollupLog {
return {
code: BAD_LOADER,
message: `Error loading "${relativeId(
id
)}": plugin load hook should return a string, a { code, map } object, or nothing/null.`
};
}
export function errCannotCallNamespace(name: string): RollupLog {
return {
code: CANNOT_CALL_NAMESPACE,
message: `Cannot call a namespace ("${name}").`
};
}
export function errCannotEmitFromOptionsHook(): RollupLog {
return {
code: CANNOT_EMIT_FROM_OPTIONS_HOOK,
message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
};
}
export function errChunkNotGeneratedForFileName(name: string): RollupLog {
return {
code: CHUNK_NOT_GENERATED,
message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.`
};
}
export function errChunkInvalid(
{ fileName, code }: { code: string; fileName: string },
exception: { loc: { column: number; line: number }; message: string }
): RollupLog {
const errorProps = {
code: CHUNK_INVALID,
message: `Chunk "${fileName}" is not valid JavaScript: ${exception.message}.`
};
augmentCodeLocation(errorProps, exception.loc, code, fileName);
return errorProps;
}
export function errCircularDependency(cyclePath: string[]): RollupLog {
return {
code: CIRCULAR_DEPENDENCY,
ids: cyclePath,
message: `Circular dependency: ${cyclePath.map(relativeId).join(' -> ')}`
};
}
export function errCircularReexport(exportName: string, exporter: string): RollupLog {
return {
code: CIRCULAR_REEXPORT,
exporter,
message: `"${exportName}" cannot be exported from "${relativeId(
exporter
)}" as it is a reexport that references itself.`
};
}
export function errCyclicCrossChunkReexport(
exportName: string,
exporter: string,
reexporter: string,
importer: string
): RollupLog {
return {
code: CYCLIC_CROSS_CHUNK_REEXPORT,
exporter,
id: importer,
message: `Export "${exportName}" of module "${relativeId(
exporter
)}" was reexported through module "${relativeId(
reexporter
)}" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "${relativeId(
importer
)}" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.`,
reexporter
};
}
export function errDeprecation(deprecation: string | RollupWarning): RollupLog {
return {
code: DEPRECATED_FEATURE,
...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
};
}
export function errDuplicateImportOptions(): RollupLog {
return {
code: DUPLICATE_IMPORT_OPTIONS,
message: 'Either use --input, or pass input path as argument'
};
}
export function errDuplicatePluginName(plugin: string): RollupLog {
return {
code: DUPLICATE_PLUGIN_NAME,
message: `The plugin name ${plugin} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).`
};
}
export function errEmptyChunk(chunkName: string): RollupLog {
return {
code: EMPTY_BUNDLE,
message: `Generated an empty chunk: "${chunkName}".`,
names: [chunkName]
};
}
export function errEval(id: string): RollupLog {
return {
code: EVAL,
id,
message: `Use of eval in "${relativeId(
id
)}" is strongly discouraged as it poses security risks and may cause issues with minification.`,
url: 'https://rollupjs.org/guide/en/#avoiding-eval'
};
}
export function errExternalSyntheticExports(id: string, importer: string): RollupLog {
return {
code: EXTERNAL_SYNTHETIC_EXPORTS,
exporter: id,
message: `External "${id}" cannot have "syntheticNamedExports" enabled (imported by "${relativeId(
importer
)}").`
};
}
export function errFailAfterWarnings(): RollupLog {
return {
code: FAIL_AFTER_WARNINGS,
message: 'Warnings occurred and --failAfterWarnings flag present.'
};
}
export function errFileNameConflict(fileName: string): RollupLog {
return {
code: FILE_NAME_CONFLICT,
message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
};
}
export function errFileReferenceIdNotFoundForFilename(assetReferenceId: string): RollupLog {
return {
code: FILE_NOT_FOUND,
message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
};
}
export function errIllegalIdentifierAsName(name: string): RollupLog {
return {
code: ILLEGAL_IDENTIFIER_AS_NAME,
message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`,
url: 'https://rollupjs.org/guide/en/#outputextend'
};
}
export function errIllegalImportReassignment(name: string, importingId: string): RollupLog {
return {
code: ILLEGAL_REASSIGNMENT,
message: `Illegal reassignment of import "${name}" in "${relativeId(importingId)}".`
};
}
export function errInputHookInOutputPlugin(pluginName: string, hookName: string): RollupLog {
return {
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
};
}
export function errCannotAssignModuleToChunk(
moduleId: string,
assignToAlias: string,
currentAlias: string
): RollupLog {
return {
code: INVALID_CHUNK,
message: `Cannot assign "${relativeId(
moduleId
)}" to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
};
}
export function errCannotBundleConfigAsEsm(originalError: Error): RollupLog {
return {
cause: originalError,
code: INVALID_CONFIG_MODULE_FORMAT,
message: `Rollup transpiled your configuration to an ES module even though it appears to contain CommonJS elements. To resolve this, you can pass the "--bundleConfigAsCjs" flag to Rollup or change your configuration to only contain valid ESM code.\n\nOriginal error: ${originalError.message}`,
stack: originalError.stack,
url: 'https://rollupjs.org/guide/en/#--bundleconfigascjs'
};
}
export function errCannotLoadConfigAsCjs(originalError: Error): RollupLog {
return {
cause: originalError,
code: INVALID_CONFIG_MODULE_FORMAT,
message: `Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
stack: originalError.stack,
url: 'https://rollupjs.org/guide/en/#--bundleconfigascjs'
};
}
export function errCannotLoadConfigAsEsm(originalError: Error): RollupLog {
return {
cause: originalError,
code: INVALID_CONFIG_MODULE_FORMAT,
message: `Node tried to load your configuration as an ES module even though it is likely CommonJS. To resolve this, change the extension of your configuration to ".cjs" or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
stack: originalError.stack,
url: 'https://rollupjs.org/guide/en/#--bundleconfigascjs'
};
}
export function errInvalidExportOptionValue(optionValue: string): RollupLog {
return {
code: INVALID_EXPORT_OPTION,
message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}".`,
url: `https://rollupjs.org/guide/en/#outputexports`
};
}
export function errIncompatibleExportOptionValue(
optionValue: string,
keys: readonly string[],
entryModule: string
): RollupLog {
return {
code: INVALID_EXPORT_OPTION,
message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(
entryModule
)}" has the following exports: ${printQuotedStringList(keys)}`,
url: 'https://rollupjs.org/guide/en/#outputexports'
};
}
export function errInternalIdCannotBeExternal(source: string, importer: string): RollupLog {
return {
code: INVALID_EXTERNAL_ID,
message: `"${source}" is imported as an external by "${relativeId(
importer
)}", but is already an existing non-external module id.`
};
}
export function errInvalidOption(
option: string,
urlHash: string,
explanation: string,
value?: string | boolean | null
): RollupLog {
return {
code: INVALID_OPTION,
message: `Invalid value ${
value !== undefined ? `${JSON.stringify(value)} ` : ''
}for option "${option}" - ${explanation}.`,
url: `https://rollupjs.org/guide/en/#${urlHash}`
};
}
export function errInvalidAddonPluginHook(hook: string, plugin: string): RollupLog {
return {
code: INVALID_PLUGIN_HOOK,
hook,
message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`,
plugin
};
}
export function errInvalidFunctionPluginHook(hook: string, plugin: string): RollupLog {
return {
code: INVALID_PLUGIN_HOOK,
hook,
message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`,
plugin
};
}
export function errInvalidRollupPhaseForAddWatchFile(): RollupLog {
return {
code: INVALID_ROLLUP_PHASE,
message: `Cannot call "addWatchFile" after the build has finished.`
};
}
export function errInvalidRollupPhaseForChunkEmission(): RollupLog {
return {
code: INVALID_ROLLUP_PHASE,
message: `Cannot emit chunks after module loading has finished.`
};
}
export function errInvalidSetAssetSourceCall(): RollupLog {
return {
code: INVALID_SETASSETSOURCE,
message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.`
};
}
export function errInvalidFormatForTopLevelAwait(
id: string,
format: InternalModuleFormat
): RollupLog {
return {
code: INVALID_TLA_FORMAT,
id,
message: `Module format "${format}" does not support top-level await. Use the "es" or "system" output formats rather.`
};
}
export function errMissingConfig(): RollupLog {
return {
code: MISSING_CONFIG,
message: 'Config file must export an options object, or an array of options objects',
url: 'https://rollupjs.org/guide/en/#configuration-files'
};
}
export function errMissingExport(
binding: string,
importingModule: string,
exporter: string
): RollupLog {
return {
binding,
code: MISSING_EXPORT,
exporter,
id: importingModule,
message: `"${binding}" is not exported by "${relativeId(exporter)}", imported by "${relativeId(
importingModule
)}".`,
url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
};
}
export function errMissingExternalConfig(file: string): RollupLog {
return {
code: MISSING_EXTERNAL_CONFIG,
message: `Could not resolve config file "${file}"`
};
}
export function errMissingGlobalName(externalId: string, guess: string): RollupLog {
return {
code: MISSING_GLOBAL_NAME,
id: externalId,
message: `No name was provided for external module "${externalId}" in "output.globals" – guessing "${guess}".`,
names: [guess],
url: 'https://rollupjs.org/guide/en/#outputglobals'
};
}
export function errImplicitDependantCannotBeExternal(
unresolvedId: string,
implicitlyLoadedBefore: string
): RollupLog {
return {
code: MISSING_IMPLICIT_DEPENDANT,
message: `Module "${relativeId(
unresolvedId
)}" that should be implicitly loaded before "${relativeId(
implicitlyLoadedBefore
)}" cannot be external.`
};
}
export function errUnresolvedImplicitDependant(
unresolvedId: string,
implicitlyLoadedBefore: string
): RollupLog {
return {
code: MISSING_IMPLICIT_DEPENDANT,
message: `Module "${relativeId(
unresolvedId
)}" that should be implicitly loaded before "${relativeId(
implicitlyLoadedBefore
)}" could not be resolved.`
};
}
export function errImplicitDependantIsNotIncluded(module: Module): RollupLog {
const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency =>
relativeId(dependency.id)
).sort();
return {
code: MISSING_IMPLICIT_DEPENDANT,
message: `Module "${relativeId(
module.id
)}" that should be implicitly loaded before ${printQuotedStringList(
implicitDependencies
)} is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
};
}
export function errMissingNameOptionForIifeExport(): RollupLog {
return {
code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`,
url: 'https://rollupjs.org/guide/en/#outputname'
};
}
export function errMissingNameOptionForUmdExport(): RollupLog {
return {
code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
message:
'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.',
url: 'https://rollupjs.org/guide/en/#outputname'
};
}
export function errMissingNodeBuiltins(externalBuiltins: string[]): RollupLog {
return {
code: MISSING_NODE_BUILTINS,
ids: externalBuiltins,
message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList(
externalBuiltins
)}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`
};
}
export function errMissingFileOrDirOption(): RollupLog {
return {
code: MISSING_OPTION,
message: 'You must specify "output.file" or "output.dir" for the build.',
url: 'https://rollupjs.org/guide/en/#outputdir'
};
}
export function errMixedExport(facadeModuleId: string, name?: string): RollupLog {
return {
code: MIXED_EXPORTS,
id: facadeModuleId,
message: `Entry module "${relativeId(
facadeModuleId
)}" is using named and default exports together. Consumers of your bundle will have to use \`${
name || 'chunk'
}.default\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.`,
url: `https://rollupjs.org/guide/en/#outputexports`
};
}
export function errModuleLevelDirective(directive: string, id: string): RollupLog {
return {
code: MODULE_LEVEL_DIRECTIVE,
id,
message: `Module level directives cause errors when bundled, "${directive}" in "${relativeId(
id
)}" was ignored.`
};
}
export function errNamespaceConflict(
binding: string,
reexportingModuleId: string,
sources: string[]
): RollupLog {
return {
binding,
code: NAMESPACE_CONFLICT,
ids: sources,
message: `Conflicting namespaces: "${relativeId(
reexportingModuleId
)}" re-exports "${binding}" from one of the modules ${printQuotedStringList(
sources.map(moduleId => relativeId(moduleId))
)} (will be ignored).`,
reexporter: reexportingModuleId
};
}
export function errNoFileSystemInBrowser(method: string): RollupLog {
return {
code: NO_FS_IN_BROWSER,
message: `Cannot access the file system (via "${method}") when using the browser build of Rollup. Make sure you supply a plugin with custom resolveId and load hooks to Rollup.`,
url: 'https://rollupjs.org/guide/en/#a-simple-example'
};
}
export function errNoTransformMapOrAstWithoutCode(pluginName: string): RollupLog {
return {
code: NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
message:
`The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
'a "code". This will be ignored.'
};
}
export function errOnlyInlineSourcemapsForStdout(): RollupLog {
return {
code: ONLY_INLINE_SOURCEMAPS,
message: 'Only inline sourcemaps are supported when bundling to stdout.'
};
}
export function errParseError(error: Error, moduleId: string): RollupLog {
let message = error.message.replace(/ \(\d+:\d+\)$/, '');
if (moduleId.endsWith('.json')) {
message += ' (Note that you need @rollup/plugin-json to import JSON files)';
} else if (!moduleId.endsWith('.js')) {
message += ' (Note that you need plugins to import files that are not JavaScript)';
}
return {
cause: error,
code: PARSE_ERROR,
id: moduleId,
message
};
}
export function errPluginError(
error: string | RollupLog,
plugin: string,
{ hook, id }: { hook?: string; id?: string } = {}
): RollupLog {
if (typeof error === 'string') error = { message: error };
if (error.code && error.code !== PLUGIN_ERROR) {
error.pluginCode = error.code;
}
error.code = PLUGIN_ERROR;
error.plugin = plugin;
if (hook) {
error.hook = hook;
}
if (id) {
error.id = id;
}
return error;
}
export function errShimmedExport(id: string, binding: string): RollupLog {
return {
binding,
code: SHIMMED_EXPORT,
exporter: id,
message: `Missing export "${binding}" has been shimmed in module "${relativeId(id)}".`
};
}
export function errSourcemapBroken(plugin: string): RollupLog {
return {
code: SOURCEMAP_BROKEN,
message: `Sourcemap is likely to be incorrect: a plugin (${plugin}) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
plugin,
url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect`
};
}
export function errInvalidSourcemapForError(
error: Error,
id: string,
column: number,
line: number,
pos: number
): RollupLog {
return {
cause: error,
code: SOURCEMAP_ERROR,
id,
loc: {
column,
file: id,
line
},
message: `Error when using sourcemap for reporting an error: ${error.message}`,
pos
};
}
export function errSyntheticNamedExportsNeedNamespaceExport(
id: string,
syntheticNamedExportsOption: boolean | string
): RollupLog {
return {
code: SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
exporter: id,
message: `Module "${relativeId(
id
)}" that is marked with \`syntheticNamedExports: ${JSON.stringify(
syntheticNamedExportsOption
)}\` needs ${
typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
? `an explicit export named "${syntheticNamedExportsOption}"`
: 'a default export'
} that does not reexport an unresolved named export of the same module.`
};
}
export function errThisIsUndefined(): RollupLog {
return {
code: THIS_IS_UNDEFINED,
message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
url: `https://rollupjs.org/guide/en/#error-this-is-undefined`
};
}
export function errUnexpectedNamedImport(
id: string,
imported: string,
isReexport: boolean
): RollupLog {
const importType = isReexport ? 'reexport' : 'import';
return {
code: UNEXPECTED_NAMED_IMPORT,
exporter: id,
message: `The named export "${imported}" was ${importType}ed from the external module "${relativeId(
id
)}" even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
url: 'https://rollupjs.org/guide/en/#outputinterop'
};
}
export function errUnexpectedNamespaceReexport(id: string): RollupLog {
return {
code: UNEXPECTED_NAMED_IMPORT,
exporter: id,
message: `There was a namespace "*" reexport from the external module "${relativeId(
id
)}" even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
url: 'https://rollupjs.org/guide/en/#outputinterop'
};
}
export function errUnknownOption(
optionType: string,
unknownOptions: string[],
validOptions: string[]
): RollupLog {
return {
code: UNKNOWN_OPTION,
message: `Unknown ${optionType}: ${unknownOptions.join(
', '
)}. Allowed options: ${validOptions.join(', ')}`
};
}
export function errEntryCannotBeExternal(unresolvedId: string): RollupLog {
return {
code: UNRESOLVED_ENTRY,
message: `Entry module "${relativeId(unresolvedId)}" cannot be external.`
};
}
export function errUnresolvedEntry(unresolvedId: string): RollupLog {
return {
code: UNRESOLVED_ENTRY,
message: `Could not resolve entry module "${relativeId(unresolvedId)}".`
};
}
export function errUnresolvedImport(source: string, importer: string): RollupLog {
return {
code: UNRESOLVED_IMPORT,
exporter: source,
id: importer,
message: `Could not resolve "${source}" from "${relativeId(importer)}"`
};
}
export function errUnresolvedImportTreatedAsExternal(source: string, importer: string): RollupLog {
return {
code: UNRESOLVED_IMPORT,
exporter: source,
id: importer,
message: `"${source}" is imported by "${relativeId(
importer
)}", but could not be resolved – treating it as an external dependency.`,
url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
};
}
export function errUnusedExternalImports(
externalId: string,
names: string[],
importers: string[]
): RollupLog {
return {
code: UNUSED_EXTERNAL_IMPORT,
exporter: externalId,
ids: importers,
message: `${printQuotedStringList(names, [
'is',
'are'
])} imported from external module "${externalId}" but never used in ${printQuotedStringList(
importers.map(importer => relativeId(importer))
)}.`,
names
};
}
export function errFailedValidation(message: string): RollupLog {
return {
code: VALIDATION_ERROR,
message
};
}
export function warnDeprecation(
deprecation: string | RollupWarning,
activeDeprecation: boolean,
options: NormalizedInputOptions
): void {
warnDeprecationWithOptions(
deprecation,
activeDeprecation,
options.onwarn,
options.strictDeprecations
);
}
export function warnDeprecationWithOptions(
deprecation: string | RollupWarning,
activeDeprecation: boolean,
warn: WarningHandler,
strictDeprecations: boolean
): void {
if (activeDeprecation || strictDeprecations) {
const warning = errDeprecation(deprecation);
if (strictDeprecations) {
return error(warning);
}
warn(warning);
}
}