I am new to Reactjs and am started learning it. I have been trying to start a basic hello world program but its failing at compilation level. Created a start up hello-word program with create-react-app hello-world it gave me a nice folder structure with bunch of files. And Here you can see the compilation error
JavaScript
x
9
1
Failed to compile
2
./src/index.js
3
Module build failed: Error: Failed to load plugin import: Cannot find module
4
'eslint-plugin-import'
5
Referenced from:
6
at Array.forEach (native)
7
at Array.reduceRight (native)
8
This error occurred during the build time and cannot be dismissed.
9
Here the error states cannot find module so i tried to install eslint plugin import ,standard ..etc but still its not worked. Below is my webpack.config.dev.js
JavaScript
1
252
252
1
// @remove-on-eject-begin
2
/**
3
* Copyright (c) 2015-present, Facebook, Inc.
4
*
5
* This source code is licensed under the MIT license found in the
6
* LICENSE file in the root directory of this source tree.
7
*/
8
// @remove-on-eject-end
9
'use strict';
10
11
const autoprefixer = require('autoprefixer');
12
const path = require('path');
13
const webpack = require('webpack');
14
const HtmlWebpackPlugin = require('html-webpack-plugin');
15
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-
16
plugin');
17
const InterpolateHtmlPlugin = require('react-dev-
18
utils/InterpolateHtmlPlugin');
19
const WatchMissingNodeModulesPlugin = require('react-dev-
20
utils/WatchMissingNodeModulesPlugin');
21
const eslintFormatter = require('react-dev-utils/eslintFormatter');
22
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
23
const getClientEnvironment = require('./env');
24
const paths = require('./paths');
25
26
27
const env = getClientEnvironment(publicUrl);
28
29
module.exports = {
30
// You may want 'eval' instead if you prefer to see the compiled output in
31
DevTools.
32
// See the discussion in https://github.com/facebookincubator/create-
33
react-app/issues/343.
34
devtool: 'cheap-module-source-map',
35
36
entry: [
37
// We ship a few polyfills by default:
38
require.resolve('./polyfills'),
39
// Include an alternative client for WebpackDevServer. A client's job is to
40
// connect to WebpackDevServer by a socket and get notified about changes.
41
// When you save a file, the client will either apply hot updates (in case
42
// of CSS changes), or refresh the page (in case of JS changes). When you
43
// make a syntax error, this client will display a syntax error overlay.
44
// Note: instead of the default WebpackDevServer client, we use a custom one
45
// to bring better experience for Create React App users. You can replace
46
// the line below with these two lines if you prefer the stock client:
47
// require.resolve('webpack-dev-server/client') + '?/',
48
// require.resolve('webpack/hot/dev-server'),
49
require.resolve('react-dev-utils/webpackHotDevClient'),
50
// Finally, this is your app's code:
51
paths.appIndexJs,
52
// We include the app code last so that if there is a runtime error during
53
// initialization, it doesn't blow up the WebpackDevServer client, and
54
// changing JS code would still trigger a refresh.
55
],
56
output: {
57
// Next line is not used in dev but WebpackDevServer crashes without it:
58
path: paths.appBuild,
59
// Add /* filename */ comments to generated require()s in the output.
60
pathinfo: true,
61
// This does not produce a real file. It's just the virtual path that is
62
// served by WebpackDevServer in development. This is the JS bundle
63
// containing code from all our entry points, and the Webpack runtime.
64
filename: 'static/js/bundle.js',
65
// There are also additional JS chunk files if you use code splitting.
66
chunkFilename: 'static/js/[name].chunk.js',
67
// This is the URL that app is served from. We use "/" in development.
68
publicPath: publicPath,
69
// Point sourcemap entries to original disk location (format as URL on
70
Windows)
71
devtoolModuleFilenameTemplate: info =>
72
path.resolve(info.absoluteResourcePath).replace(/\/g, '/'),
73
},
74
resolve: {
75
76
modules: ['node_modules', paths.appNodeModules].concat(
77
// It is guaranteed to exist because we tweak it in `env.js`
78
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
79
),
80
81
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
82
alias: {
83
// @remove-on-eject-begin
84
// Resolve Babel runtime relative to react-scripts.
85
// It usually still works on npm 3 without this but it would be
86
// unfortunate to rely on, as react-scripts could be symlinked,
87
// and thus babel-runtime might not be resolvable from the source.
88
'babel-runtime': path.dirname(
89
require.resolve('babel-runtime/package.json')
90
),
91
// @remove-on-eject-end
92
// Support React Native Web
93
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-
94
with-react-native-for-web/
95
'react-native': 'react-native-web',
96
},
97
plugins: [
98
// Prevents users from importing files from outside of src/ (or
99
node_modules/).
100
101
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
102
],
103
},
104
module: {
105
strictExportPresence: true,
106
rules: [
107
// TODO: Disable require.ensure as it's not a standard language feature.
108
// We are waiting for https://github.com/facebookincubator/create-react-
109
app/issues/2176.
110
// { parser: { requireEnsure: false } },
111
112
// First, run the linter.
113
// It's important to do this before Babel processes the JS.
114
{
115
test: /.(js|jsx)$/,
116
enforce: 'pre',
117
use: [
118
{
119
options: {
120
formatter: eslintFormatter,
121
eslintPath: require.resolve('eslint'),
122
// @remove-on-eject-begin
123
baseConfig: {
124
extends: [require.resolve('eslint-config-react-app')],
125
},
126
ignore: false,
127
useEslintrc: false,
128
// @remove-on-eject-end
129
},
130
loader: require.resolve('eslint-loader'),
131
},
132
],
133
include: paths.appSrc,
134
},
135
{
136
// "oneOf" will traverse all following loaders until one will
137
// match the requirements. When no loader matches it will fall
138
// back to the "file" loader at the end of the loader list.
139
oneOf: [
140
141
142
{
143
test: [/.bmp$/, /.gif$/, /.jpe?g$/, /.png$/],
144
loader: require.resolve('url-loader'),
145
options: {
146
limit: 10000,
147
name: 'static/media/[name].[hash:8].[ext]',
148
},
149
},
150
// Process JS with Babel.
151
{
152
test: /.(js|jsx)$/,
153
include: paths.appSrc,
154
loader: require.resolve('babel-loader'),
155
options: {
156
// @remove-on-eject-begin
157
babelrc: false,
158
presets: [require.resolve('babel-preset-react-app')],
159
160
cacheDirectory: true,
161
},
162
},
163
// "postcss" loader applies autoprefixer to our CSS.
164
// "css" loader resolves paths in CSS and adds assets as dependencies.
165
// "style" loader turns CSS into JS modules that inject <style> tags.
166
// In production, we use a plugin to extract that CSS to a file, but
167
// in development "style" loader enables hot editing of CSS.
168
{
169
test: /.css$/,
170
use: [
171
require.resolve('style-loader'),
172
{
173
loader: require.resolve('css-loader'),
174
options: {
175
importLoaders: 1,
176
},
177
},
178
{
179
loader: require.resolve('postcss-loader'),
180
options: {
181
// Necessary for external CSS imports to work
182
183
ident: 'postcss',
184
plugins: () => [
185
require('postcss-flexbugs-fixes'),
186
autoprefixer({
187
browsers: [
188
'>1%',
189
'last 4 versions',
190
'Firefox ESR',
191
'not ie < 9', // React doesn't support IE8 anyway
192
],
193
flexbox: 'no-2009',
194
}),
195
],
196
},
197
},
198
],
199
},
200
201
{
202
// Exclude `js` files to keep "css" loader working as it injects
203
// it's runtime that would otherwise processed through "file"
204
loader.
205
// Also exclude `html` and `json` extensions so they get processed
206
// by webpacks internal loaders.
207
exclude: [/.js$/, /.html$/, /.json$/],
208
loader: require.resolve('file-loader'),
209
options: {
210
name: 'static/media/[name].[hash:8].[ext]',
211
},
212
},
213
],
214
},
215
216
],
217
},
218
plugins: [
219
220
new InterpolateHtmlPlugin(env.raw),
221
// Generates an `index.html` file with the <script> injected.
222
new HtmlWebpackPlugin({
223
inject: true,
224
template: paths.appHtml,
225
}),
226
227
new webpack.NamedModulesPlugin(),
228
229
new webpack.DefinePlugin(env.stringified),
230
231
new webpack.HotModuleReplacementPlugin(),
232
233
new CaseSensitivePathsPlugin(),
234
235
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
236
237
new webpack.IgnorePlugin(/^./locale$/, /moment$/),
238
],
239
240
node: {
241
dgram: 'empty',
242
fs: 'empty',
243
net: 'empty',
244
tls: 'empty',
245
child_process: 'empty',
246
},
247
248
performance: {
249
hints: false,
250
},
251
};
252
Can any one guide me how to come out of this build error.
Advertisement
Answer
This means eslint-plugin-import not available in your node_modules
.
A fresh npm install eslint-plugin-import
and restart the application should fix this issue.
If that didn’t fix, try upgrading your npm
version:
JavaScript
1
2
1
npm install -g npm@latest
2