javascript - Why does Webpack build of React web app fail when project is built in a different folder? -
i have react project built using webpack. weird issue when run react app in original folder builds , runs without error. when copy files in folder, paste in new folder , try build same project fails. have tried changing folder name, changing config files reflect new folder name, fails in app.js , points error in render method. few points note:
- i havent hardcoded paths
- i have cleaned node modules , rebuilt project groundup including cleaning npm cache.
- the same project works in original folder without errors.
the error follows:
version: webpack 2.2.1 time: 1520ms asset size chunks chunk names app.js 219 kb 0 [emitted] main index.html 636 bytes [emitted] chunk {0} app.js (main) 208 kb [entry] [rendered] [1] (webpack)/buildin/global.js 509 bytes {0} [built] [32] ./src/app.js 783 bytes {0} [built] [failed] [1 error] [33] (webpack)-dev-server/client?http://0.0.0.0:8080 4.16 kb {0} [built] [34] ./~/ansi-regex/index.js 135 bytes {0} [built] [35] ./~/punycode/punycode.js 14.7 kb {0} [built] [36] ./~/querystring-es3/decode.js 2.51 kb {0} [built] [38] ./~/querystring-es3/index.js 127 bytes {0} [built] [40] ./~/sockjs-client/lib/entry.js 244 bytes {0} [built] [47] ./~/sockjs-client/lib/main.js 11.9 kb {0} [built] [49] ./~/sockjs-client/lib/transport-list.js 613 bytes {0} [built] [66] ./~/strip-ansi/index.js 161 bytes {0} [built] [68] ./~/url/url.js 23.3 kb {0} [built] [69] ./~/url/util.js 314 bytes {0} [built] [70] (webpack)-dev-server/client/socket.js 897 bytes {0} [built] [72] multi (webpack)-dev-server/client?http://0.0.0.0:8080 ./src/app.js 40 bytes {0} [built] + 58 hidden modules error in ./src/app.js module build failed: syntaxerror: unexpected token (39:2) 37 | // }); 38 | reactdom.render( > 39 | <div>hello</div>, | ^ 40 | document.getelementbyid('content'), 41 | ); 42 | @ multi (webpack)-dev-server/client?http://0.0.0.0:8080 ./src/app.js child html-webpack-plugin "index.html": chunk {0} index.html 542 kb [entry] [rendered] [0] ./~/lodash/lodash.js 540 kb {0} [built] [1] (webpack)/buildin/global.js 509 bytes {0} [built] [2] (webpack)/buildin/module.js 517 bytes {0} [built] [3] ./~/html-webpack-plugin/lib/loader.js!./src/index.html 1.32 kb {0} [built] webpack: failed compile.
the above error doesn't happen when running in original folder. issue here?
your .babelrc
file in root of project directory, , thats webpack looks use loaders , presets. can workaround using following config
{ use: [ { loader: 'babel-loader', options: { babelrc: false, presets: [require.resolve('babel-preset-react-app')], // <- whatever preset wish cachedirectory: true, } } ], test: /\.js$/, exclude: /node_modules/ },
Comments
Post a Comment