I’m receiving a weird error npm ERR! code 1
when trying to launch the dev server or run a build.
I’ve researched this problem for a while with no success whatsoever.
The problem manifests itself when I try to import an image in a js file from the src folder.
JavaScript
x
2
1
import myImage from '../assets/images/my-image.svg'
2
Or when I try to import sass partials from the sass folder into app.scss.
JavaScript
1
2
1
@import './components/myComponent
2
Here is the NPM error message:
JavaScript
1
8
1
npm ERR! code 1
2
npm ERR! path /Users/david/Documents/Code/Project/crowdfund-product-page
3
npm ERR! command failed
4
npm ERR! command sh -c webpack serve
5
6
npm ERR! A complete log of this run can be found in:
7
npm ERR! /Users/david/.npm/_logs/2021-03-26T11_43_57_401Z-debug.log
8
Here is a piece of the error output from the terminal:
JavaScript
1
578
578
1
},
2
properties: {
3
asset: { '$ref': '#/definitions/AssetParserOptions' },
4
'asset/inline': { '$ref': '#/definitions/EmptyParserOptions' },
5
'asset/resource': { '$ref': '#/definitions/EmptyParserOptions' },
6
'asset/source': { '$ref': '#/definitions/EmptyParserOptions' },
7
javascript: { '$ref': '#/definitions/JavascriptParserOptions' },
8
'javascript/auto': { '$ref': '#/definitions/JavascriptParserOptions' },
9
'javascript/dynamic': { '$ref': '#/definitions/JavascriptParserOptions' },
10
'javascript/esm': { '$ref': '#/definitions/JavascriptParserOptions' }
11
}
12
},
13
Path: {
14
description: 'The output directory as **absolute path** (required).',
15
type: 'string',
16
absolutePath: true
17
},
18
Pathinfo: {
19
description: 'Include comments with information about the modules.',
20
anyOf: [ { enum: [Array] }, { type: 'boolean' } ]
21
},
22
Performance: {
23
description: 'Configuration for web performance recommendations.',
24
anyOf: [
25
{ enum: [Array] },
26
{ '$ref': '#/definitions/PerformanceOptions' }
27
]
28
},
29
PerformanceOptions: {
30
description: 'Configuration object for web performance recommendations.',
31
type: 'object',
32
additionalProperties: false,
33
properties: {
34
assetFilter: {
35
description: 'Filter function to select assets that are checked.',
36
instanceof: 'Function',
37
tsType: 'Function'
38
},
39
hints: {
40
description: 'Sets the format of the hints: warnings, errors or nothing at all.',
41
enum: [Array]
42
},
43
maxAssetSize: {
44
description: 'File size limit (in bytes) when exceeded, that webpack will provide performance hints.',
45
type: 'number'
46
},
47
maxEntrypointSize: {
48
description: 'Total size of an entry point (in bytes).',
49
type: 'number'
50
}
51
}
52
},
53
Plugins: {
54
description: 'Add additional plugins to the compiler.',
55
type: 'array',
56
items: {
57
description: 'Plugin of type object or instanceof Function.',
58
anyOf: [ [Object], [Object] ]
59
}
60
},
61
Profile: {
62
description: 'Capture timing information for each module.',
63
type: 'boolean'
64
},
65
PublicPath: {
66
description: "The 'publicPath' specifies the public URL address of the output files when referenced in a browser.",
67
anyOf: [
68
{ enum: [Array] },
69
{ '$ref': '#/definitions/RawPublicPath' }
70
]
71
},
72
RawPublicPath: {
73
description: "The 'publicPath' specifies the public URL address of the output files when referenced in a browser.",
74
anyOf: [
75
{ type: 'string' },
76
{
77
instanceof: 'Function',
78
tsType: '((pathData: import("../lib/Compilation").PathData, assetInfo?: import("../lib/Compilation").AssetInfo) => string)'
79
}
80
]
81
},
82
RecordsInputPath: {
83
description: 'Store compiler state to a json file.',
84
anyOf: [ { enum: [Array] }, { type: 'string', absolutePath: true } ]
85
},
86
RecordsOutputPath: {
87
description: 'Load compiler state from a json file.',
88
anyOf: [ { enum: [Array] }, { type: 'string', absolutePath: true } ]
89
},
90
RecordsPath: {
91
description: 'Store/Load compiler state from/to a json file. This will result in persistent ids of modules and chunks. An absolute path is expected. `recordsPath` is used for `recordsInputPath` and `recordsOutputPath` if they left undefined.',
92
anyOf: [ { enum: [Array] }, { type: 'string', absolutePath: true } ]
93
},
94
Resolve: {
95
description: 'Options for the resolver.',
96
oneOf: [ { '$ref': '#/definitions/ResolveOptions' } ]
97
},
98
ResolveAlias: {
99
description: 'Redirect module requests.',
100
anyOf: [
101
{ type: 'array', items: [Object] },
102
{ type: 'object', additionalProperties: [Object] }
103
]
104
},
105
ResolveLoader: {
106
description: 'Options for the resolver when resolving loaders.',
107
oneOf: [ { '$ref': '#/definitions/ResolveOptions' } ]
108
},
109
ResolveOptions: {
110
description: 'Options object for resolving requests.',
111
type: 'object',
112
additionalProperties: false,
113
properties: {
114
alias: { '$ref': '#/definitions/ResolveAlias' },
115
aliasFields: {
116
description: 'Fields in the description file (usually package.json) which are used to redirect requests inside the module.',
117
type: 'array',
118
items: [Object]
119
},
120
byDependency: {
121
description: 'Extra resolve options per dependency category. Typical categories are "commonjs", "amd", "esm".',
122
type: 'object',
123
additionalProperties: [Object]
124
},
125
cache: {
126
description: 'Enable caching of successfully resolved requests (cache entries are revalidated).',
127
type: 'boolean'
128
},
129
cachePredicate: {
130
description: 'Predicate function to decide which requests should be cached.',
131
instanceof: 'Function',
132
tsType: "((request: import('enhanced-resolve').ResolveRequest) => boolean)"
133
},
134
cacheWithContext: {
135
description: 'Include the context information in the cache identifier when caching.',
136
type: 'boolean'
137
},
138
conditionNames: {
139
description: 'Condition names for exports field entry point.',
140
type: 'array',
141
items: [Object]
142
},
143
descriptionFiles: {
144
description: 'Filenames used to find a description file (like a package.json).',
145
type: 'array',
146
items: [Object]
147
},
148
enforceExtension: {
149
description: 'Enforce the resolver to use one of the extensions from the extensions option (User must specify requests without extension).',
150
type: 'boolean'
151
},
152
exportsFields: {
153
description: 'Field names from the description file (usually package.json) which are used to provide entry points of a package.',
154
type: 'array',
155
items: [Object]
156
},
157
extensions: {
158
description: 'Extensions added to the request when trying to find the file.',
159
type: 'array',
160
items: [Object]
161
},
162
fallback: {
163
description: 'Redirect module requests when normal resolving fails.',
164
oneOf: [Array]
165
},
166
fileSystem: {
167
description: 'Filesystem for the resolver.',
168
tsType: "(import('../lib/util/fs').InputFileSystem)"
169
},
170
fullySpecified: {
171
description: "Treats the request specified by the user as fully specified, meaning no extensions are added and the mainFiles in directories are not resolved (This doesn't affect requests from mainFields, aliasFields or aliases).",
172
type: 'boolean'
173
},
174
importsFields: {
175
description: 'Field names from the description file (usually package.json) which are used to provide internal request of a package (requests starting with # are considered as internal).',
176
type: 'array',
177
items: [Object]
178
},
179
mainFields: {
180
description: 'Field names from the description file (package.json) which are used to find the default entry point.',
181
type: 'array',
182
items: [Object]
183
},
184
mainFiles: {
185
description: 'Filenames used to find the default entry point if there is no description file or main field.',
186
type: 'array',
187
items: [Object]
188
},
189
modules: {
190
description: 'Folder names or directory paths where to find modules.',
191
type: 'array',
192
items: [Object]
193
},
194
plugins: {
195
description: 'Plugins for the resolver.',
196
type: 'array',
197
cli: [Object],
198
items: [Object]
199
},
200
preferAbsolute: {
201
description: "Prefer to resolve server-relative URLs (starting with '/') as absolute paths before falling back to resolve in 'resolve.roots'.",
202
type: 'boolean'
203
},
204
preferRelative: {
205
description: 'Prefer to resolve module requests as relative request and fallback to resolving as module.',
206
type: 'boolean'
207
},
208
resolver: {
209
description: 'Custom resolver.',
210
tsType: "(import('enhanced-resolve').Resolver)"
211
},
212
restrictions: {
213
description: 'A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.',
214
type: 'array',
215
items: [Object]
216
},
217
roots: {
218
description: "A list of directories in which requests that are server-relative URLs (starting with '/') are resolved.",
219
type: 'array',
220
items: [Object]
221
},
222
symlinks: {
223
description: 'Enable resolving symlinks to the original location.',
224
type: 'boolean'
225
},
226
unsafeCache: {
227
description: 'Enable caching of successfully resolved requests (cache entries are not revalidated).',
228
anyOf: [Array]
229
},
230
useSyncFileSystemCalls: {
231
description: 'Use synchronous filesystem calls for the resolver.',
232
type: 'boolean'
233
}
234
}
235
},
236
ResolvePluginInstance: {
237
description: 'Plugin instance.',
238
type: 'object',
239
additionalProperties: true,
240
properties: {
241
apply: {
242
description: 'The run point of the plugin, required method.',
243
instanceof: 'Function',
244
tsType: "(resolver: import('enhanced-resolve').Resolver) => void"
245
}
246
},
247
required: [ 'apply' ]
248
},
249
RuleSetCondition: {
250
description: 'A condition matcher.',
251
cli: { helper: true },
252
anyOf: [
253
{ instanceof: 'RegExp', tsType: 'RegExp' },
254
{ type: 'string' },
255
{
256
type: 'object',
257
additionalProperties: false,
258
properties: [Object]
259
},
260
{
261
instanceof: 'Function',
262
tsType: '((value: string) => boolean)'
263
},
264
{ '$ref': '#/definitions/RuleSetConditions' }
265
]
266
},
267
RuleSetConditionAbsolute: {
268
description: 'A condition matcher matching an absolute path.',
269
cli: { helper: true },
270
anyOf: [
271
{ instanceof: 'RegExp', tsType: 'RegExp' },
272
{ type: 'string', absolutePath: true },
273
{
274
type: 'object',
275
additionalProperties: false,
276
properties: [Object]
277
},
278
{
279
instanceof: 'Function',
280
tsType: '((value: string) => boolean)'
281
},
282
{ '$ref': '#/definitions/RuleSetConditionsAbsolute' }
283
]
284
},
285
RuleSetConditionOrConditions: {
286
description: 'One or multiple rule conditions.',
287
cli: { helper: true },
288
anyOf: [
289
{ '$ref': '#/definitions/RuleSetCondition' },
290
{ '$ref': '#/definitions/RuleSetConditions' }
291
]
292
},
293
RuleSetConditionOrConditionsAbsolute: {
294
description: 'One or multiple rule conditions matching an absolute path.',
295
cli: { helper: true },
296
anyOf: [
297
{ '$ref': '#/definitions/RuleSetConditionAbsolute' },
298
{ '$ref': '#/definitions/RuleSetConditionsAbsolute' }
299
]
300
},
301
RuleSetConditions: {
302
description: 'A list of rule conditions.',
303
type: 'array',
304
items: { description: 'A rule condition.', oneOf: [ [Object] ] }
305
},
306
RuleSetConditionsAbsolute: {
307
description: 'A list of rule conditions matching an absolute path.',
308
type: 'array',
309
items: {
310
description: 'A rule condition matching an absolute path.',
311
oneOf: [ [Object] ]
312
}
313
},
314
RuleSetLoader: {
315
description: 'A loader request.',
316
type: 'string',
317
minLength: 1
318
},
319
RuleSetLoaderOptions: {
320
description: 'Options passed to a loader.',
321
anyOf: [ { type: 'string' }, { type: 'object' } ]
322
},
323
RuleSetRule: {
324
description: 'A rule description with conditions and effects for modules.',
325
type: 'object',
326
additionalProperties: false,
327
properties: {
328
compiler: {
329
description: 'Match the child compiler name.',
330
oneOf: [Array]
331
},
332
dependency: { description: 'Match dependency type.', oneOf: [Array] },
333
descriptionData: {
334
description: 'Match values of properties in the description file (usually package.json).',
335
type: 'object',
336
additionalProperties: [Object]
337
},
338
enforce: {
339
description: 'Enforce this rule as pre or post step.',
340
enum: [Array]
341
},
342
exclude: {
343
description: 'Shortcut for resource.exclude.',
344
oneOf: [Array]
345
},
346
generator: {
347
description: 'The options for the module generator.',
348
type: 'object'
349
},
350
include: {
351
description: 'Shortcut for resource.include.',
352
oneOf: [Array]
353
},
354
issuer: {
355
description: 'Match the issuer of the module (The module pointing to this module).',
356
oneOf: [Array]
357
},
358
issuerLayer: {
359
description: 'Match layer of the issuer of this module (The module pointing to this module).',
360
oneOf: [Array]
361
},
362
layer: {
363
description: 'Specifies the layer in which the module should be placed in.',
364
type: 'string'
365
},
366
loader: { description: 'Shortcut for use.loader.', oneOf: [Array] },
367
mimetype: {
368
description: 'Match module mimetype when load from Data URI.',
369
oneOf: [Array]
370
},
371
oneOf: {
372
description: 'Only execute the first matching rule in this array.',
373
type: 'array',
374
items: [Object]
375
},
376
options: {
377
description: 'Shortcut for use.options.',
378
cli: [Object],
379
oneOf: [Array]
380
},
381
parser: {
382
description: 'Options for parsing.',
383
type: 'object',
384
additionalProperties: true
385
},
386
realResource: {
387
description: 'Match the real resource path of the module.',
388
oneOf: [Array]
389
},
390
resolve: {
391
description: 'Options for the resolver.',
392
type: 'object',
393
oneOf: [Array]
394
},
395
resource: {
396
description: 'Match the resource path of the module.',
397
oneOf: [Array]
398
},
399
resourceFragment: {
400
description: 'Match the resource fragment of the module.',
401
oneOf: [Array]
402
},
403
resourceQuery: {
404
description: 'Match the resource query of the module.',
405
oneOf: [Array]
406
},
407
rules: {
408
description: 'Match and execute these rules when this rule is matched.',
409
type: 'array',
410
items: [Object]
411
},
412
sideEffects: {
413
description: 'Flags a module as with or without side effects.',
414
type: 'boolean'
415
},
416
test: {
417
description: 'Shortcut for resource.test.',
418
oneOf: [Array]
419
},
420
type: {
421
description: 'Module type to use for the module.',
422
type: 'string'
423
},
424
use: {
425
description: 'Modifiers applied to the module when rule is matched.',
426
oneOf: [Array]
427
}
428
}
429
},
430
RuleSetRules: {
431
description: 'A list of rules.',
432
type: 'array',
433
items: { description: 'A rule.', anyOf: [ [Object], [Object] ] }
434
},
435
RuleSetUse: {
436
description: 'A list of descriptions of loaders applied.',
437
anyOf: [
438
{ type: 'array', items: [Object] },
439
{
440
instanceof: 'Function',
441
tsType: '((data: { resource: string, realResource: string, resourceQuery: string, issuer: string, compiler: string }) => RuleSetUseItem[])'
442
},
443
{ '$ref': '#/definitions/RuleSetUseItem' }
444
]
445
},
446
RuleSetUseItem: {
447
description: 'A description of an applied loader.',
448
anyOf: [
449
{
450
type: 'object',
451
additionalProperties: false,
452
properties: [Object]
453
},
454
{
455
instanceof: 'Function',
456
tsType: '((data: object) => RuleSetUseItem|RuleSetUseItem[])'
457
},
458
{ '$ref': '#/definitions/RuleSetLoader' }
459
]
460
},
461
ScriptType: {
462
description: 'This option enables loading async chunks via a custom script type, such as script type="module".',
463
enum: [ false, 'text/javascript', 'module' ]
464
},
465
SnapshotOptions: {
466
description: 'Options affecting how file system snapshots are created and validated.',
467
type: 'object',
468
additionalProperties: false,
469
properties: {
470
buildDependencies: {
471
description: 'Options for snapshotting build dependencies to determine if the whole cache need to be invalidated.',
472
type: 'object',
473
additionalProperties: false,
474
properties: [Object]
475
},
476
immutablePaths: {
477
description: 'List of paths that are managed by a package manager and contain a version or hash in its path so all files are immutable.',
478
type: 'array',
479
items: [Object]
480
},
481
managedPaths: {
482
description: 'List of paths that are managed by a package manager and can be trusted to not be modified otherwise.',
483
type: 'array',
484
items: [Object]
485
},
486
module: {
487
description: 'Options for snapshotting dependencies of modules to determine if they need to be built again.',
488
type: 'object',
489
additionalProperties: false,
490
properties: [Object]
491
},
492
resolve: {
493
description: 'Options for snapshotting dependencies of request resolving to determine if requests need to be re-resolved.',
494
type: 'object',
495
additionalProperties: false,
496
properties: [Object]
497
},
498
resolveBuildDependencies: {
499
description: 'Options for snapshotting the resolving of build dependencies to determine if the build dependencies need to be re-resolved.',
500
type: 'object',
501
additionalProperties: false,
502
properties: [Object]
503
}
504
}
505
},
506
SourceMapFilename: {
507
description: "The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.",
508
type: 'string',
509
absolutePath: false
510
},
511
SourcePrefix: {
512
description: 'Prefixes every line of the source in the bundle with this string.',
513
type: 'string'
514
},
515
StatsOptions: {
516
description: 'Stats options object.',
517
type: 'object',
518
additionalProperties: false,
519
properties: {
520
all: {
521
description: 'Fallback value for stats options when an option is not defined (has precedence over local webpack defaults).',
522
type: 'boolean'
523
},
524
assets: { description: 'Add assets information.', type: 'boolean' },
525
assetsSort: {
526
description: 'Sort the assets by that field.',
527
type: 'string'
528
},
529
assetsSpace: {
530
description: 'Space to display assets (groups will be collapsed to fit this space).',
531
type: 'number'
532
},
533
builtAt: {
534
description: 'Add built at time information.',
535
type: 'boolean'
536
},
537
cached: {
538
description: "Add information about cached (not built) modules (deprecated: use 'cachedModules' instead).",
539
type: 'boolean'
540
},
541
cachedAssets: {
542
description: 'Show cached assets (setting this to `false` only shows emitted files).',
543
type: 'boolean'
544
},
545
cachedModules: {
546
description: 'Add information about cached (not built) modules.',
547
type: 'boolean'
548
},
549
children: { description: 'Add children information.', type: 'boolean' },
550
chunkGroupAuxiliary: {
551
description: 'Display auxiliary assets in chunk groups.',
552
type: 'boolean'
553
},
554
chunkGroupChildren: {
555
description: 'Display children of chunk groups.',
556
type: 'boolean'
557
},
558
chunkGroupMaxAssets: {
559
description: 'Limit of assets displayed in chunk groups.',
560
type: 'number'
561
},
562
chunkGroups: {
563
description: 'Display all chunk groups with the corresponding bundles.',
564
type: 'boolean'
565
},
566
chunkModules: {
567
description: 'Add built modules information to chunk information.',
568
type: 'boolean'
569
},
570
chunkModulesSpace: {
571
description: 'Space to display chunk modules (groups will be collapsed to fit this space, value is in number of modules/group).',
572
type: 'number'
573
},
574
chunkOrigins: {
575
description: 'Add the origins of chunks and chunk merging info.',
576
type: 'boolean'
577
},
578
webpack.config.js file:
JavaScript
1
88
88
1
const path = require('path')
2
const HtmlWebpackPlugin = require('html-webpack-plugin')
3
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
4
const ESLintPlugin = require('eslint-webpack-plugin')
5
const CopyPlugin = require('copy-webpack-plugin')
6
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
7
8
const isDevelopment = process.env.NODE_ENV !== 'production'
9
10
module.exports = {
11
mode: isDevelopment ? 'development' : 'production',
12
entry: './src/index.js',
13
output: {
14
path: path.resolve(__dirname, 'dist'),
15
publicPath: '',
16
filename: isDevelopment ? '[name].js' : '[name].[hash].js',
17
},
18
devServer: {
19
contentBase: './src',
20
open: 'Google Chrome',
21
compress: true,
22
port: 9000,
23
hot: true,
24
},
25
module: {
26
rules: [
27
{
28
test: /.js$/,
29
exclude: /(node_modules)/,
30
use: 'babel-loader',
31
},
32
{
33
test: /.(sa|sc|c)ss$/,
34
use: [
35
{
36
loader: MiniCssExtractPlugin.loader,
37
},
38
{
39
loader: 'css-loader',
40
options: {
41
sourceMap: true,
42
},
43
},
44
{
45
loader: 'postcss-loader',
46
},
47
{
48
loader: 'sass-loader',
49
options: {
50
sourceMap: true,
51
implementation: require('sass'),
52
},
53
},
54
],
55
},
56
{
57
test: /.(?:ico|gif|png|jpg|jpeg)$/i,
58
type: 'asset/resource',
59
generator: {
60
filename: 'assets/images/[hash][ext][query]',
61
},
62
},
63
{
64
test: /.(woff(2)?|eot|ttf|otf|svg|)$/,
65
type: 'asset/inline',
66
generator: {
67
filename: 'fonts/[hash][ext][query]',
68
},
69
},
70
],
71
},
72
plugins: [
73
new CleanWebpackPlugin(),
74
new HtmlWebpackPlugin({
75
title: 'Webpack template',
76
template: '/src/index.html',
77
filename: 'index.html',
78
}),
79
new CopyPlugin({
80
patterns: [{ from: 'src/assets/static', to: 'assets/static' }],
81
}),
82
new MiniCssExtractPlugin({
83
filename: 'main.css',
84
}),
85
new ESLintPlugin(),
86
],
87
}
88
package.json file:
JavaScript
1
36
36
1
"scripts": {
2
"start": "webpack serve",
3
"dev": "cross-env NODE_ENV=development webpack --config webpack.config.js",
4
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js",
5
"deploy": "npm run build && gh-pages -d dist"
6
},
7
"dependencies": {
8
"autoprefixer": "^10.2.5",
9
"cssnano": "^4.1.10",
10
"gh-pages": "^3.1.0"
11
},
12
"devDependencies": {
13
"@babel/core": "^7.13.10",
14
"@babel/eslint-parser": "^7.13.10",
15
"@babel/preset-env": "^7.13.12",
16
"babel-loader": "^8.2.2",
17
"clean-webpack-plugin": "^3.0.0",
18
"copy-webpack-plugin": "^8.1.0",
19
"cross-env": "^7.0.3",
20
"css-loader": "^5.2.0",
21
"eslint": "^7.22.0",
22
"eslint-config-airbnb-base": "^14.2.1",
23
"eslint-plugin-import": "^2.22.1",
24
"eslint-webpack-plugin": "^2.5.3",
25
"file-loader": "^6.2.0",
26
"html-webpack-plugin": "^5.3.1",
27
"mini-css-extract-plugin": "^1.3.9",
28
"postcss-loader": "^5.2.0",
29
"sass": "^1.32.8",
30
"sass-loader": "^11.0.1",
31
"style-loader": "^2.0.0",
32
"webpack": "^5.28.0",
33
"webpack-cli": "^4.5.0",
34
"webpack-dev-server": "^3.11.2"
35
},
36
Advertisement
Answer
Problem solved by removing the generator from the font import in webpack.config.js, going from this :
JavaScript
1
6
1
test: /.(woff(2)?|eot|ttf|otf|svg|)$/,
2
type: 'asset/inline'
3
generator: {
4
filename: 'assets/images/[hash][ext][query]'
5
}
6
To this :
JavaScript
1
3
1
test: /.(woff(2)?|eot|ttf|otf|svg|)$/,
2
type: 'asset/inline'
3