Cannot GET manifest.json react webpack - reactjs

I've been running a TS react app with WebPack and get an issue where it will not load manifest.json and so will not load the tab icon:
I have it set up with the typical react app structure where you have the default public folder with the favicon.ico, manifest.json, logo pngs, etc and then the src folder with the app as follows:
My-App
dist/
node_modules/
public/
favicon.ico
index.html
manifest.json
robots.txt
...
src/
Here's my webpack.config.json for reference:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const InterpolateHtmlPlugin = require('interpolate-html-plugin')
module.exports = {
entry: path.resolve(__dirname, 'src', 'index.tsx'),
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
devtool: "source-map",
mode: "development",
devServer: {
historyApiFallback: true,
contentBase: path.resolve(__dirname, 'dist'),
port: 3000
},
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx']
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ['ts-loader']
},
{
test: /\.s(a|c)ss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[local]'
}
}
},
'sass-loader'
]
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.html/,
use: ['html-loader']
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/,
exclude: /node_modules/,
use: ['file-loader?name=[name].[ext]'] // ?name=[name].[ext] is only necessary to preserve the original file name
},
{
test: /\.woff(2)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
name: './font/[hash].[ext]',
mimetype: 'application/font-woff'
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'public', 'index.html'),
filename: './index.html',
manifest: "./manifest.json"
}),
// new InterpolateHtmlPlugin({
// PUBLIC_URL: 'static' // can modify `static` to another name or get it from `process`
// }),
]
};
As you can see I tried using the InterpolateHtml plugin but no matter what I did I would get this tap error as follows
[webpack-cli] TypeError: Cannot read property 'tap' of undefined
at /home/myufa/home/personal/vibe-mill/frontend/node_modules/interpolate-html-plugin/index.js:35:63
at Hook.eval [as call] (eval at create (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:100:1)
at Hook.CALL_DELEGATE [as _call] (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
at Compiler.newCompilation (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/lib/Compiler.js:988:26)
at /home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/lib/Compiler.js:1029:29
at Hook.eval [as callAsync] (eval at create (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
at Compiler.compile (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/lib/Compiler.js:1024:28)
at /home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/lib/Compiler.js:471:12
at Compiler.readRecords (/home/myufa/home/personal/vibe-mill/frontend/node_modules/webpack/lib/Compiler.js:866:11)
npm ERR! code ELIFECYCLE
This is my first time using Webpack so I'm not sure how to debug. Any help would be much appreciated!

Related

Webpack throws error for a file in node_modules

When I try to run Webpack, it throws an error:
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> #charset "UTF-8";
| .k-theme-test-class,
| .k-common-test-class {
# ./src/App.js 19:0-52
# ./src/index.js
# multi #babel/polyfill ./src/index.js
At first I thought the issue is the # symbol and then I realized it is not supposed to even run through node_modules, right?
My webpack.config.js is:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// const PrettierPlugin = require('prettier-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
module.exports = {
entry: ['#babel/polyfill', './src/index.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
chunkFilename: '[id].js',
publicPath: '/',
},
devServer: {
historyApiFallback: true,
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.s?css$/,
exclude: /node_modules/,
oneOf: [
{
test: /\.module\.s?css$/,
exclude: /node_modules/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]___[hash:base64:5]',
},
sourceMap: true,
},
},
{ loader: 'sass-loader' },
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['autoprefixer', {}]],
},
},
},
],
},
{
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
{
test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
loader: 'url-loader?limit=10000&name=img/[name].[ext]',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, '/src/index.html'),
filename: 'index.html',
inject: 'body',
}),
new ESLintPlugin(),
new MiniCssExtractPlugin(),
// new PrettierPlugin({
// configFile: '.prettierrc',
// }),
],
};
If I remove the 3 css-related exclude: I get the following error:
ERROR in ./node_modules/#progress/kendo-theme-default/dist/all.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Internal Error: Incompatible units: 'px' and 'em'.
at C:\www\Svila\SvilaReact\svila-erp\node_modules\webpack\lib\NormalModule.js:316:20
at C:\www\Svila\SvilaReact\svila-erp\node_modules\loader-runner\lib\LoaderRunner.js:367:11
at C:\www\Svila\SvilaReact\svila-erp\node_modules\loader-runner\lib\LoaderRunner.js:233:18
at context.callback (C:\www\Svila\SvilaReact\svila-erp\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at Object.callback (C:\www\Svila\SvilaReact\svila-erp\node_modules\sass-loader\dist\index.js:62:7)
at Object.done [as callback] (C:\www\Svila\SvilaReact\svila-erp\node_modules\neo-async\async.js:8069:18)
at options.error (C:\www\Svila\SvilaReact\svila-erp\node_modules\node-sass\lib\index.js:293:32)
# ./src/App.js 19:0-52
# ./src/index.js
# multi #babel/polyfill ./src/index.js
where the culprit is:
border-width: max( 1px, .015em );. This is invalid sass and can be generally fixed by wrapping with calc border-width: calc(max( 1px, .015em )); as mentioned here
So I have the following questions in order of importance:
Why does this file get piped through the loaders, given it has a exclude: /node_modules/?
Are files from external libraries supposed to be piped through the loaders/plugins in Webpack, or do they have another way of including themselves in the dev/production version?
Why is the .js for babel-loader excluding /node_modules/ but not s?css? (I see such tendency around random webpack.config.js files)
Interestingly enough, the culprit line margin-left: calc(24px + 1em); is actually a valid css according to World Wide Web Consortium. That makes me wonder - should a plain css be piped at all through a sass-loader? Maybe this is not entirely correct, or is it?
What is the right way to fix it?

load dependent modules in chunks with react loadable

The Application (build in "react": "15.4.1" ) has some dependent modules.Dependent Modules are referred in package.json : "git+https://git.xyz.net/myApp/ui/myModule.ui.git#v0.0.4",.
myModule has same logical entities.
Now I applied lazy loading on myModule using "react-loadable": "4.0.3",.
I am getting below chunks when i run npm start on myModule:
0.my-Module-ui.js
1.my-Module-ui.js
2.my-Module-ui.js
my-Module-ui.js
webpack file for myModule :
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: ['./src/index.js'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'my-Module-ui.js',
// chunkFilename: '[name].js',
libraryTarget: 'umd',
publicPath: '/',
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
},
module: {
loaders: [
{
test: /\.(json)$/,
loaders: [
'json-loader'
]
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
query:{
presets: ["es2015" , "stage-0", "react"],
plugins: ["transform-runtime"],
}
},
{
test: /\.(sass|less|css)$/,
loaders: ['style-loader', 'css-loader', 'less-loader']
},
// Load images
{ test: /\.jpg/, loader: "url-loader?limit=10000&mimetype=image/jpg" },
{ test: /\.gif/, loader: "url-loader?limit=10000&mimetype=image/gif" },
{ test: /\.png/, loader: "url-loader?limit=10000&mimetype=image/png" },
{ test: /\.svg/, loader: "url-loader?limit=10000&mimetype=image/svg" },
// Load fonts
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
{ test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
]
},
// plugins: [
// new webpack.optimize.UglifyJsPlugin({comments: false, compress: { warnings: false }, screw_ie8: true})
// ]
};
Webpack version in package.json : "webpack": "^3.0.0",
Issue:
when I load the main app,My Main App home screen has some widget which uses the dependent modules doesn't gets loaded but we see error in console.
2.my-Module-ui.js:1 Uncaught SyntaxError: Unexpected token <
my-Module-ui.js:109 Uncaught (in promise) Error: Loading chunk 2 failed.
at HTMLScriptElement.onScriptComplete (my-Module-ui.js:109)
I have tried everything since yesterday...Please help me out on this ,Please let me know if any others details are required

Not able to run react project

I am new to reactjs. i am trying to write webpack.
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './main.js',
output: {
path: path.join(__dirname, '/bundle'),
filename: 'index_bundle.js'
},
devServer: {
inline: true,
port: 3000
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
options: {
includePaths: ["absolute/path/a", "absolute/path/b"]
}
}]
}
]
},
plugins:[
new HtmlWebpackPlugin({
template: './index.html'
})
]
}
Html Webpack Plugin:
Error: Child compilation failed:
Entry module not found: Error: Can't resolve 'F:\react-app\index.html' in 'F:\ react-app':
Error: Can't resolve 'F:\react-app\index.html' in 'F:\react-app'
compiler.js:141
[react-app]/[html-webpack-plugin]/lib/compiler.js:141:18
Compiler.js:306
[react-app]/[webpack]/lib/Compiler.js:306:11
Compiler.js:631
[react-app]/[webpack]/lib/Compiler.js:631:15
Hook.js:154 AsyncSeriesHook.lazyCompileHook
[react-app]/[tapable]/lib/Hook.js:154:20
Compiler.js:628
[react-app]/[webpack]/lib/Compiler.js:628:31
Hook.js:154 AsyncSeriesHook.lazyCompileHook
[react-app]/[tapable]/lib/Hook.js:154:20
Compilation.js:1325
[react-app]/[webpack]/lib/Compilation.js:1325:35
plugins:[
new HtmlWebpackPlugin({
hash:'true'
template: './index.html'
})
]
Put hash to true and make sure you have the correct location of the template file.

React app looking for bundle.js in component folder not project root

The errors I get below are shown in the console after I refresh on a nested route (register/email-confirmation). Whereas non-nested routes do not get this error.
I think the main problem is that it's searching for bundle.js and the image in the nested route path, as opposed to the root path.
The errors in my console:
GET http://localhost:3002/register/bundle.js net::ERR_ABORTED
Refused to execute script from 'http://localhost:3002/register/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
GET http://localhost:3002/register/a5e694be93a1c3d22b85658bdc30008b.png 404 (Not Found)
My webpack.config.js:
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BUILD_PATH = path.resolve( __dirname, "./client/build" );
const SOURCE_PATH = path.resolve( __dirname, "./client/src" );
const PUBLIC_PATH = "/";
...
module.exports = {
devtool: 'eval-source-map',
context: SOURCE_PATH,
entry: ['babel-polyfill', SOURCE_PATH + '/index.jsx'],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: [/node_modules/, /server/],
use: {
loader: 'babel-loader',
options: {
presets: ['env', 'es2015', 'react', 'stage-1', 'stage-0', 'stage-2'],
plugins: [
'transform-decorators-legacy',
'transform-es2015-destructuring',
'transform-es2015-parameters',
'transform-object-rest-spread'
]
}
}
},
{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader"
}]
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {}
}
]
},
],
},
output: {
path: BUILD_PATH,
filename: "bundle.js",
},
devServer: {
compress: true,
port: 3002,
historyApiFallback: true,
contentBase: BUILD_PATH,
publicPath: PUBLIC_PATH,
},
plugins: [
new webpack.DefinePlugin(appConstants),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, 'client/src/index.html'),
inject: true
}),
],
watch: true,
}
I don't know about this bug, but I highly recommend using fuse-box
fuse-box is the future of the build systems, within few minutes you will be running your project with high speed hot reload and many others utitilites...
check this react example seed, it's incredibly amazing..

PostCSS Module Parse Failed on Windows 10 build

I'm running into an interesting error with my react build. My configuration runs perfectly fine on my Mac, but I get the following error when running on my Windows 10 computer:
ERROR in ./~/react-toolbox/lib/app_bar/theme.css
Module parse failed: C:\cygwin64\home\username\projectname\node_modules\react-toolbox\lib\app_bar\theme.css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| :root {
| --palette-red-50: rgb(255, 235, 238 );
| --palette-red-100: rgb(255, 205, 210);
# ./~/react-toolbox/lib/app_bar/index.js 16:13-35
# ./src/containers/app/app.js
# ./src/index.js
# multi react-hot-loader/patch ./src/index.js
Here's my Webpack 2 Config
'use strict'
const webpack = require('webpack')
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const postcssImport = require('postcss-import')
const postcssCssnext = require('postcss-cssnext')
// configure source and distribution folder paths
const publicFolder = 'public'
const buildFolder = 'build'
module.exports = {
entry: {
'app': [
'react-hot-loader/patch',
'./src/index.js'
]
},
resolve: {
//Allows us to leave off the file extension when importing
extensions: ['.js', '.json', '.jsx']
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: '/node_modules/',
loader: 'eslint-loader',
},
{
test: /\.(js|jsx)$/,
exclude: '/node_modules/',
loader: 'babel-loader'
},
{
test: /\.css$/,
include: [
/(node_modules)\/react-toolbox/,
path.join(__dirname, 'src')
],
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: 'inline',
plugins: function() {
return [
postcssImport({ addDependencyTo: webpack }),
postcssCssnext({
browsers: ['last 2 versions', '> 5%'],
compress: true,
})
]
},
},
}
]
})
}
]
},
plugins: [
new ExtractTextPlugin({
filename: '[name].bundle.css',
allChunks: true
}),
new CopyWebpackPlugin([{
from: path.join(__dirname, publicFolder, 'index.html'),
to: path.join(__dirname, buildFolder, 'index.html')
}]),
new CopyWebpackPlugin([{
from: path.join(__dirname, publicFolder, 'demo.html'),
to: path.join(__dirname, buildFolder, 'demo.html')
}]),
new CopyWebpackPlugin([{
from: path.join(__dirname, publicFolder, 'demo.js'),
to: path.join(__dirname, buildFolder, 'demo.js')
}]),
new webpack.NamedModulesPlugin()
],
output: {
path: path.resolve(__dirname, buildFolder),
filename: '[name].js',
publicPath: '/'
},
devtool: 'eval',
devServer: {
// files are served from this folder
contentBase: path.join(__dirname, 'build'),
// support HTML5 History API for react router
historyApiFallback: true,
// listen to port 5000, change this to another port if another server
// is already listening on this port
port: 5000,
//match the output 'publicPath'
publicPath: '/',
//Proxies to match requests to our Django API endpoints
proxy: {
'/api': {
target: 'http://localhost:4000'
}
},
hot: true
}
}
And for good measure, here's my .babelrc config
{
"presets": [
[ "es2015", { "modules": false } ],
"latest",
"react"
],
"plugins": ["react-hot-loader/babel", "syntax-dynamic-import"],
"env": {
"test": {
"plugins": ["dynamic-import-node"]
}
}
}
No idea why the error occurs when compiling on Windows 10 but works perfectly on my Mac. I can't seem to find any current info regarding this issue for either PostCSS or Webpack 2.
Any ideas?
just remove
include: [
/(node_modules)\/react-toolbox/,
path.join(__dirname, 'src')
]
from test: /\.css$/ rule

Resources