Good evening,
I'm working on a project written in NodeJS. It uses an express server and many other dependencies like angular, googlemaps, tika, karma, etc.
A few weeks ago I've got the order to make the webpage (localhost) faster by implementing webpack. It bundles all stylesheets and scripts into one file.
After a lot of work to solve all dependencies I've got the app running even though many errors couldn't be found with google. e.g. "java" is a sub dependency which calls "node-gyp rebuild" which is doomed to failure on windows because node-gyp need python and c++ compiler. After installing Windows SDK, VS 2015, etc. I could fix this problem switching to the 32 bit version of node (instead of 64 bit).
After repairing all dependencies I switched to the 64 bit version to solve another problem. The webpack config is due to the amount of dependencies (which needs "alias" entries) quite long.
Two weeks ago I started to implement a developer mode so you can change code and webpack-dev-server automatically rebuilds the bundle file. Therefore I followed a tutorial from SurviveJS.
I've got it easily running after the tutorial. But for a presentation I wanted to clone the Github repository and install all dependencies a second time so I can be sure that the project works. But this time a new error appeared when I was running webpack or webpack-dev-server which couldn't be solved with my previous tricks:
Path_to_project\demo\n2o>..\node_modules\.bin\webpack --config webpack.config.js
Error: No module factory available for dependency type: ModuleDependency
at Compilation.addModuleDependencies (Path_to_project\demo\node_modules\webpack\lib\Compilation.js:181:20)
at Compilation.processModuleDependencies (Path_to_project\demo\node_modules\webpack\lib\Compilation.js:170:7)
at Compilation.moduleReady (Path_to_project\demo\node_modules\webpack\lib\Compilation.js:412:9)
at Compilation.<anonymous> (Path_to_project\demo\node_modules\webpack\lib\Compilation.js:408:16)
at Path_to_project\demo\node_modules\webpack\lib\Compilation.js:123:4
at Array.forEach (native)
at callback (Path_to_project\demo\node_modules\webpack\lib\Compilation.js:122:12)
at Compilation.<anonymous> (Path_to_project\demo\node_modules\webpack\lib\Compilation.js:140:10)
at DependenciesBlock.<anonymous> (Path_to_project\demo\node_modules\webpack\lib\NormalModule.js:115:10)
at DependenciesBlock.onModuleBuild (Path_to_project\demo\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10)
at nextLoader (Path_to_project\demo\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
at Path_to_project\demo\node_modules\webpack\node_modules\webpack-core\lib\NormalModuleMixin.js:259:5
at Storage.finished (Path_to_project\demo\node_modules\webpack\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:16)
at Path_to_project\demo\node_modules\webpack\node_modules\enhanced-resolve\node_modules\graceful-fs\graceful-fs.js:76:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
When I remove all plugins from the webpack config the error disappears but obviously running the app fails because the angular-webpack-plugin is missing and most of the dependencies are not loaded by webpack. What could be the reason for this failure? I tried different versions of webpack (1.12.2 worked out for me after discovering this fix in an issue on Github) and webpack-dev-server.
I would appreciate your help,
Thomas Kellermeier
Files (webpack.config.js, package.json):
webpack.config.js (webpack)
The settings for webpack-dev-server are at the end of the config
var path = require('path');
var AngularPlugin = require('angular-webpack-plugin');
var webpack = require("webpack");
require("css-selector-tokenizer");
var merge = require('webpack-merge');
const TARGET = process.env.npm_lifecycle_event;
common = {
entry: 'n2o',
output: {
path: 'public/app',
filename: 'n2o.min.js',
publicPath: 'app/'
},
externals: {
"jquery": "jQuery"
},
resolve: {
root: [
// Directories containing modules
path.resolve('public'),
path.resolve('public', 'assets/libs'),
path.resolve('public', 'components'),
path.resolve('public', 'components/settings'),
path.resolve('public', 'components/splitapp'),
path.resolve('public', 'components/register'),
path.resolve('public', 'shared/postContent'),
path.resolve('public', 'shared'),
// Needed for webpack-dev-server modules
path.resolve('public', '../../node_modules')
],
modulesDirectories:['public/assets/libs'],
'dev-tool':'eval',
alias: {
// Replace module names with belonging file names
n2o$: 'app.module',
ngFileUpload$: 'ng-file-upload',
toaster$: 'angularjs-toaster',
ngCookies$: 'angular-cookies',
'ui.router$': __dirname+'/public/assets/libs/angular-ui-router/release/angular-ui-router.js',
'jQuery$': __dirname+'/public/assets/libs/jquery/dist/jquery.js',
registration$: 'register',
ngAnimate$: 'angular-animate',
'mm.foundation$': __dirname+'/public/assets/libs/angular-foundation/mm-foundation.js',
vcRecaptcha$:'angular-recaptcha',
filters$: 'postContentController',
'cfp.hotkeys$':'angular-hotkeys',
'angulartics.google.analytics$':__dirname+'/public/assets/libs/angulartics/dist/angulartics-ga.min.js',
splitapp$:'splitappController',
register$:'registerController',
'ngTouch$':'angular-touch',
'ui-rangeSlider$':__dirname+'/public/assets/libs/angular-rangeslider/angular.rangeSlider.js',
ngSanitize:'angular-sanitize',
settingsModule: 'settingsMasterController',
ngTagsInput$:'ng-tags-input',
'chart.js$':'angular-chart.js',
// Webpack-dev-server dependency
'inherits':__dirname+'\\..\\node_modules\\inherits',
n2o: path.resolve('public'),
ngRoute$: 'angular-route'
}
},
module: {
loaders: [{
// Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output
// Rename the file using the asset hash
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)/,
loader: 'file'
}, {
// Allow loading html through js
test: /\.html$/,
loader: 'raw'
}, {
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.json$/,
loader: "json-loader"
}]
},
plugins: [
// Make angular variable available, take angular.module() as requires and
// resolve modules using angular conventions.
new AngularPlugin()
]
};
// For using the development mode the webpack-dev-server has to run with
// following config.
if(TARGET === 'start-dev-server' || !TARGET) {
common.output.publicPath = 'http://localhost:9090/app/'
module.exports = merge(common, {
devtool: 'eval-source-map',
debug: true,
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
quiet: true,
host: process.env.HOST,
port: '9090'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
})
} else {
module.exports = merge(common, {
plugins: [
new webpack.optimize.UglifyJsPlugin({
minimize: true,
sourceMap: false,
mangle: false,
compress: {
warnings: false
}
})
]
})
}
package.json (dependencies)
[...]
"scripts": {
"compile-production": "webpack --config webpack.config.js",
"start-dev-server": "webpack-dev-server --config webpack.config.js",
"start-dev-mode": "start node n2o/app.js & npm run start-dev-server",
"install-webpack": "npm install webpack#1.12.2 -g & npm install webpack-dev-server#1.14.0 -g",
[...]
},
"dependencies": {
"MD5": "^1.2.1",
"adm-zip": "^0.4.7",
"aws-sdk": "^2.1.34",
"body-parser": "^1.9.2",
"bower": "^1.3.1",
"compression": "^1.5.0",
"cookie-parser": "^1.3.3",
"elasticsearch": "^9.0.0",
"express": "^4.10.1",
"express-session": "^1.10.2",
"facebook-node-sdk": "^0.2.0",
"get-down": "^0.5.0",
"gnip": "~0.2.1",
"googlemaps": "^0.1.20",
"hdb": "^0.4.1",
"html-pdf": "^1.2.0",
"json2csv": "^2.2.1",
"limiter": "^1.0.5",
"lodash": "^3.7.0",
"mocha": "~2.2.1",
"moment": "^2.9.0",
"morgan": "^1.4.1",
"multer": "~0.1.8",
"node-ipc": "^1.1.13",
"node-tika": "^0.0.1",
"oauth": "^0.9.12",
"oauth-request": "0.0.1",
"passport": "^0.2.2",
"passport-local": "~1.0.0",
"phantom": "*",
"q": "^1.1.2",
"request": "^2.53.0",
"response-time": "^2.3.1",
"sanitize-html": "^1.6.1",
"string-format": "^0.5.0",
"stylus": "0.42.3",
"swig": "^1.4.2",
"tika": "^1.3.0",
"tough-cookie": "^0.12.1",
"twin-bcrypt": "^2.1.1",
"twit": "^1.1.20",
"underscore": "~1.8.2",
"unzip": "^0.1.11",
"webdriver-manager": "^7.0.1",
"winston": "^0.9.0"
},
"devDependencies": {
"angular-webpack-plugin": "0.0.3",
"babel-loader": "^5.3.2",
"bower-webpack-plugin": "^0.1.8",
"chai": "^1.10.0",
"chai-as-promised": "^4.1.1",
"css-loader": "^0.21.0",
"css-selector-tokenizer": "^0.5.4",
"exports-loader": "^0.6.2",
"file-loader": "^0.8.4",
"jasmine-node": "~1.14.5",
"json-loader": "^0.5.2",
"karma": "^0.12.16",
"karma-chrome-launcher": "^0.1.4",
"karma-coverage": "~0.3.1",
"karma-firefox-launcher": "~0.1.4",
"karma-jasmine": "^0.1.5",
"ng-annotate-webpack-plugin": "^0.1.2",
"protractor": "^1.7.0",
"raw-loader": "^0.5.1",
"should": "^5.0.0",
"style-loader": "^0.12.3",
"supertest": "^0.15.0",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.14.0",
"webpack-merge": "^0.3.2"
}
[...]
Related
I failed to deploy my create react app to heroku. Error log is below.
-----> Build
Running build (yarn)
yarn run v1.22.10
$ react-scripts build
Creating an optimized production build...
Failed to compile.
Failed to load config "airbnb" to extend from.
Referenced from: /tmp/build_49ca30fd/.eslintrc.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
This is my eslint.js.
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'airbnb',
'airbnb/hooks',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:#typescript-eslint/recommended',
'plugin:#typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
parser: '#typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
project: './tsconfig.eslint.json',
sourceType: 'module',
tsconfigRootDir: __dirname,
},
plugins: [
'react',
'#typescript-eslint',
'import',
'jsx-a11y',
'react-hooks',
'prettier',
],
root: true,
rules: {
'import/no-cycle': 'off',
'no-use-before-define': 'off',
'no-alert': 'off',
'#typescript-eslint/no-use-before-define': ['error'],
'lines-between-class-members': [
'error',
'always',
{
exceptAfterSingleLine: true,
},
],
'no-void': [
'error',
{
allowAsStatement: true,
},
],
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: '*',
next: 'return',
},
],
'#typescript-eslint/no-unused-vars': [
'warn',
{
vars: 'all',
args: 'after-used',
argsIgnorePattern: '_',
ignoreRestSiblings: false,
varsIgnorePattern: '_',
},
],
'#typescript-eslint/no-unsafe-member-access': ['warn'],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'react/jsx-filename-extension': [
'error',
{
extensions: ['.jsx', '.tsx'],
},
],
'react/jsx-props-no-spreading': ['off'],
'lines-between-class-members': [
'error',
'always',
{
exceptAfterSingleLine: true,
},
],
},
overrides: [
{
files: ['*.tsx'],
rules: {
'react/prop-types': 'off',
},
},
],
settings: {
'import/resolver': {
node: {
paths: ['src'],
},
},
},
}
I use style guide of airbnb with eslint and prettier in my app. I installed them to devDependencies. My pacakage.json is below.
{
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/react-fontawesome": "^0.1.14",
"#hookform/resolvers": "^2.4.0",
"#loadable/component": "^5.14.1",
"#material-ui/core": "^4.11.4",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.58",
"#types/date-fns": "^2.6.0",
"#types/node": "^15.0.1",
"#types/react": "^17.0.4",
"#types/react-dom": "^17.0.3",
"#types/styled-components": "^5.1.9",
"axios": "^0.21.1",
"camelcase-keys": "^6.2.2",
"date-fns": "^2.21.1",
"express": "^4.17.1",
"express-favicon": "^2.0.1",
"file-saver": "^2.0.5",
"firebase": "^8.4.3",
"heroku-ssl-redirect": "^0.1.1",
"little-state-machine": "^3.1.4",
"path": "^0.12.7",
"qs": "^6.10.1",
"react": "^16.13.1",
"react-circular-progressbar": "^2.0.4",
"react-devtools": "^4.13.0",
"react-dom": "^16.13.1",
"react-hook-form": "^7.3.5",
"react-media": "^1.10.0",
"react-responsive": "^8.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-sortablejs": "^6.0.0",
"sanitize-html": "^2.3.3",
"snakecase-keys": "^4.0.1",
"sortablejs": "^1.13.0",
"source-map-explorer": "^2.5.2",
"styled-components": "^5.2.3",
"styled-media-query": "^2.1.2",
"typescript": "~4.2.4",
"typesync": "^0.8.0",
"uuid": "^8.3.2",
"yup": "^0.32.9"
},
"devDependencies": {
"#types/eslint": "^7.2.10",
"#types/eslint-plugin-prettier": "^3.1.0",
"#types/express": "^4.17.11",
"#types/file-saver": "^2.0.2",
"#types/loadable__component": "^5.13.3",
"#types/prettier": "2.2.3",
"#types/qs": "^6.9.6",
"#types/react-devtools": "^3.6.0",
"#types/react-responsive": "^8.0.2",
"#types/react-router-dom": "^5.1.7",
"#types/sanitize-html": "^2.3.1",
"#types/snakecase-keys": "^2.1.0",
"#types/sortablejs": "^1.10.6",
"#types/uuid": "^8.3.0",
"#types/yup": "^0.29.11",
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"dotenv": "^8.2.0",
"eslint": "^7.2.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^1.7.0",
"prettier": "2.2.1",
}
}
When heroku deployed an app, heroku remove devDependencies. I think this is the reason. I tried to set YARN_PRODUCTION env as false. Then, I succeeded.
But, because devDependencies is installed, bundle size is bigger. I want to avoid it.
How do I handle devDependencies in deploying app using eslint and prettier to heroku?
Just stumbled on this issue and couldn't resolve it after an entire day knocking about the web. Had to disable eslint-webpack-plugin in production builds:
create file .env.production
open file and add DISABLE_ESLINT_PLUGIN=true
During CI you can still run yarn lint or whatever your linting script with no problems and avoid this webpack issue that only happens on yarn build
Sources:
GitHub Issue
CRA Advanced Configuration
CRA .env files
Heroku supports custom build script, in which you can set the environment variable directly:
"scripts": {
...
"build": "react-scripts build",
"heroku-postbuild": "DISABLE_ESLINT_PLUGIN=true react-scripts build"
},
piouson's answer does the job, however i find it cleaner to use the following solution as it is (at least I believe) Heroku-specific problem and .env.production file could influence other potential production servers.
I am creating a separate repo for sharable UI component. I am using styled-component. When I am locally publishing the package using npm link. It's throwing error.
Error is explained here.
Project
|
+-- node_modules
|
+-- styled-component v4.0.2
|
+-- ui-component
|
+-- styled-component v4.1.1
There are couple of ways to fix it as if mention in link.
npm dedupe (Not suitable for dev environment as it's not work well with npm link ).
Setting up your webpack (some of the project will be using create-react-app so they don't have access to webpack).
I have two though running in my mind.
First, both the solution kind of forcing end user to do something at your end. I want to make it like other npm package where you just install and use it without telling user to do something in configuration level.
Second, Why I have to even do that. I have setup everything in webpack. I have ask webpack to not to use it's own dependency for the particular package rather use the end user package.
How other npm packages are working which depends on parent dependency but they use own dependancy in dev process. like react
Here is files from my sharable UI component library.
Package.json
{
"name": "ui-component",
"version": "1.0.0",
"description": "Shareable web UI component",
"main": "build/index.js",
"scripts": {
"dev": "start-storybook -p 6006",
"build": "webpack",
"build:storybook": "build-storybook",
"test": "jest --env=jsdom",
"lint": "eslint"
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
},
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!storybook-static/**/*.{js,jsx}",
"!congif/**/*.{js,jsx}"
],
"setupFiles": [
"<rootDir>/src/enzymeSetup.js"
],
"testMatch": [
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"testPathIgnorePatterns": [
"<rootDir>/__tests__/setup/"
],
"moduleNameMapper": {
"^#theme": "<rootDir>/src/theme.js",
"^#validation": "<rootDir>/src/validation/index.js",
"^#helper": "<rootDir>/src/helper.js"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node",
"mjs"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"npm run lint --fix",
"cross-env CI=true npm test -- --coverage --bail --findRelatedTests"
]
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#material-ui/core": "^3.5.1",
"#material-ui/icons": "^3.0.1",
"react": "^16.6.3",
"react-router-dom": "^4.3.1",
"styled-components": "^4.1.1"
},
"devDependencies": {
"#babel/core": "^7.1.6",
"babel-core": "7.0.0-bridge.0",
"#babel/preset-env": "^7.1.6",
"#babel/preset-react": "^7.0.0",
"#storybook/addon-actions": "^4.0.7",
"#storybook/addon-centered": "^4.0.7",
"#storybook/addon-info": "^4.0.7",
"#storybook/addon-links": "^4.0.7",
"#storybook/addon-options": "^4.0.7",
"#storybook/addons": "^4.0.7",
"#storybook/components": "^4.0.7",
"#storybook/react": "^4.0.7",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"css-loader": "^1.0.1",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"eslint": "^5.9.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"file-loader": "^2.0.0",
"husky": "^1.1.2",
"jest": "^23.6.0",
"lint-staged": "^8.0.4",
"react-dom": "^16.6.3",
"react-router-dom": "^4.3.1",
"storybook-styled-components": "^1.1.2",
"style-loader": "^0.23.1",
"webpack": "^4.26.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
},
"peerDependencies": {
"react": "^16.5.2",
"styled-components": "^4.1.1"
}
}
webpack
const path = require ('path');
module.exports = {
entry: {
main: './src/index.js',
},
output: {
path: path.resolve(__dirname, './build'),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
}],
}
],
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
}
}
}
},
plugins: [],
resolve: {
alias: {
'#theme': path.resolve(__dirname, './src/theme.js'),
'#validation': path.resolve(__dirname, './src/validation/index.js'),
'#helper': path.resolve(__dirname, './src/helper.js'),
}
},
externals: {
'react': 'commonjs react', // this line is just to use the React dependency of our parent-testing-project instead of using our own React.
'styled-components': 'commonjs styled-components' // this line is just to use the React dependency of our parent-testing-project instead of using our own styled-component.
}
}
My parent app is using styled-components ^4.0.2 and my sharable ui library using styled-components "styled-components": "^4.1.1".
I have had a entries in peerDependencies as well as in webpack. struggling with it more than a day any help would highly appreciated.
See this FAQ entry in the official styled-components documentation. In most cases, adding an alias to the webpack configuration is enough to overcome the issue:
resolve: {
+ alias: {
+ "styled-components": path.resolve("./node_modules", "styled-components"),
+ }
}
I spent hours trying various things to overcome this issue myself, including everything in the styled-components docs with no luck at all. Nothing worked until I found this suggestion on GitHub.
Adding the below to your Webpack config tells it to use a single runtime for all of your entrypoints, instead of creating a new runtime for each.
optimization: {
runtimeChunk: {
name: "vendor"
},
....
I also run into this issue, somehow I think you can't load two version of styled-components sometimes even when they are the same version, ex. 4.4.1.
So in the end, i have to use peerDependencies, luckily i have control on all the repos, so I relocated the styled-components to peerDependencies for my core libraries. And then rely on only one copy in the implementation repo.
I can still smell things not right here, but so far i can only get the ThemeProvider to work this way across different repos.
I am having a big issue with my react project with dotnet core 2.0 and webpack. I use dotnet run command in the terminal and shows some info like this. In the Chrome console, some information keeps producing, just like what is shown in the picture below. This information is produced by the webpack module in the react node_module directory and can someone point out how I can fix this problem? Thanks!
here are some information I can offer:
terminal information
chrome console output
The package.json file:
{ "name": "dotnetcore", "private": true, "version": "0.0.0", "homepage": "/app/canteen/employee", "devDependencies": {
"#types/history": "4.6.0",
"#types/react": "15.0.35",
"#types/react-dom": "15.5.1",
"#types/react-hot-loader": "3.0.3",
"#types/react-router": "4.0.12",
"#types/react-router-dom": "4.0.5",
"#types/webpack-env": "1.13.0",
"aspnet-webpack": "^2.0.1",
"aspnet-webpack-react": "^3.0.0",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"css-loader": "0.28.4",
"event-source-polyfill": "0.0.9",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"react": "15.6.1",
"react-dom": "15.6.1",
"react-hot-loader": "3.0.0-beta.7",
"react-router-dom": "4.1.1",
"style-loader": "0.18.2",
"typescript": "2.4.1",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"moment": "^2.18.1",
"react-datetime": "^2.10.1",
"react-mobile-datepicker": "^3.0.6",
"react-mobile-picker": "^0.1.10",
"react-redux": "^5.0.6",
"react-router": "^4.2.0",
"react-scripts": "1.0.13",
"react-time": "^4.3.0",
"redux": "^3.7.2" } }
The webpack.config.js file
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const bundleOutputDir = './wwwroot/dist';
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
stats: { modules: false },
// entry: { 'main': './ClientApp/index.js' },
entry: { 'main': './ClientApp/boot.tsx' },
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/'
},
module: {
rules: [
{ test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
{ test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{ test: /\.js?$/, loader: 'babel-loader', exclude: /node_modules/,
query:
{
presets:['react','es2015']
}
},
]
},
plugins: [
new CheckerPlugin(),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin()
// new webpack.optimize.UglifyJsPlugin(),
// new ExtractTextPlugin('site.css')
])
}];
};
I had the same problem and almost the same webpack setup (we're both using the dotnet core starting template).
I cannot explain what causes the constant reloading but I was able to resolve it by "cleaning" my build files before or on each run of dotnet run. It appears that dotnet run is running the basic webpack command once when it fires. This means your front end files get built again (in ClientApp/dist and wwwroot/dist). If you delete all these files before running dotnet run, then the problem goes away. (warning: don't delete the vendor.* files as the main webpack config file will not rebuild those. You need the webpack.config.vendor.js script for those and that does not get autorun when you run dotnet run).
You can automate this deleting/cleaning process with the clean-webpack-plugin. Here's a snippet of what my webpack.config.js looks like using that plugin:
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = (env) => {
const clientBundleOutputDir = './wwwroot/dist';
const serverBundleOutputDir = './ClientApp/dist';
const cleanOptions = {
options: {
exclude: ['vendor.js', 'vendor.css', 'vendor-manifest.json'],
verbose: true,
},
pathsToClean: [clientBundleOutputDir, serverBundleOutputDir],
};
//.....
const clientBundleConfig = {
// ... some webpack settings ...
plugins: [
//.... array of some plugins....,
new CleanWebpackPlugin(cleanOptions.pathsToClean, cleanOptions.options),
],
// ... some more webpack settings ...
}
// ....
return [clientBundleConfig];
}
One caveat with this approach - I have found using this technique suffers in that dotnet run will run through the webpack script (which deletes your files and rebuilds them) and fires up the kestrel server and browser to run your app. Kestrel kicks in and the page attempts to load before webpack finishes rebuilding your files so the first page you see in your browser see will complain that it can't find your app's JS files. So you have to wait a few seconds for webpack to finish and then reload the page. It's not ideal but at least the constant reloading is gone.
Instead of modifying Webpack to clean all files every time, you can just apply this solution when you spot that Webpack enters into this Hot Module Replacement (HMR) loop. I noticed that this happens when you rename files, causing the HMR mechanism gets confused. You can apply the solution from my answer here.
My solution to a constant rebuild was to 'rm -rf node_modules' and 'npm install' again.
I'm kind of desperate here.
I'm working on a React application and use webpack to compile my bundle.js.
The problem is when i try to compile it for "production" i end up with a really nasty error :
"Minified React error #105; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=105&args[]=HardwareKeyboardArrowDown for the full message or use the non-minified dev environment for full errors and additional helpful warnings."
Followed by a bunch of
"Uncaught TypeError: Cannot read property '__reactInternalInstance$qw6tjofxg1o' of null"
When i set my node.env to developement ('NODE_ENV': JSON.stringify('developement') ), it's working fine.
The link in the error says : "A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object" but i don't have any problem in dev mode, so i don't think its coming from my code and i can't find where i should look to solve this problem since dev mode doesn't tell anything more to me...
Here are my webpack config & package.json :
const webpack = require('webpack');
const path = require('path');
const buildPath = path.resolve(__dirname, 'build');
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const TransferWebpackPlugin = require('transfer-webpack-plugin');
const config = {
entry: [
'./src/app/app.js'
],
// Render source-map file for final build
devtool: 'source-map',
debug: true,
// output config
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/'
},
plugins: [
// Define production build to allow React to strip out unnecessary checks
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
// Minify the bundle
new webpack.optimize.UglifyJsPlugin({
compress: {
// suppresses warnings, usually from module minification
warnings: false,
},
}),
// Allows error warnings but does not stop compiling.
new webpack.NoErrorsPlugin(),
// Transfer Files
],
module: {
loaders: [
{
test: /\.js$/, // All .js files
loaders: ['babel-loader'], // react-hot is like browser sync and babel loads jsx and es6-7
exclude: [nodeModulesPath],
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
include: /flexboxgrid/
},
{
test: /\.json$/, loader: "json-loader",
},
{ test: /\.scss?$/,
loader: 'style!css!sass',
include: path.join(__dirname, 'src', 'styles') },
{ test: /\.png$/,
loader: 'file' },
{ test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file'}
],
resolve: {
extensions: ['', '.js', '.jsx', '.css', '.json']
}
},
};
module.exports = config;
{
"name": "material-ui-example-webpack",
"version": "0.16.0",
"description": "Sample project that uses Material-UI",
"repository": {
"type": "git",
"url": "https://github.com/callemall/material-ui.git"
},
"scripts": {
"start": "webpack-dev-server --config webpack-dev-server.config.js --host $IP --port $PORT --hot --progress --inline --colors",
"clean-public": "npm run remove-public && mkdir public",
"remove-public": "node_modules/.bin/rimraf ./public",
"build:html": "babel-node tools/buildHtml.js",
"heroku-prebuild": "npm install && npm-run-all clean-public build:html",
"heroku-postbuild": "babel-node tools/build.js",
"prod-start": "babel-node tools/publicServer.js"
},
"private": true,
"devDependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-2": "^6.18.0",
"html-webpack-plugin": "^2.24.1",
"npm-run-all": "1.8.0",
"redux-devtools": "^3.4.0",
"redux-devtools-dock-monitor": "^1.1.2",
"redux-devtools-log-monitor": "^1.3.0",
"rimraf": "2.5.2",
"transfer-webpack-plugin": "^0.1.4",
"webpack": "^1.13.3",
"webpack-dev-server": "^1.16.2"
},
"dependencies": {
"axios": "^0.16.1",
"babel-cli": "6.8.0",
"babel-loader": "^6.2.8",
"babel-polyfill": "6.8.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"babel-preset-stage-2": "^6.24.1",
"cheerio": "^0.20.0",
"colors": "1.1.2",
"compression": "^1.6.1",
"css-loader": "^0.27.3",
"express": "^4.15.2",
"json-loader": "^0.5.4",
"lint": "^1.1.2",
"material-ui": "^0.17.1",
"ncp": "^2.0.0",
"npm-run-all": "1.8.0",
"open": "0.0.5",
"react": "^15.4.1",
"react-component-queries": "^2.1.1",
"react-dom": "^15.4.1",
"react-fittext": "https://github.com/gianu/react-fittext",
"react-flexbox-grid": "^1.0.2",
"react-html-parser": "^1.0.3",
"react-masonry-component": "^5.0.5",
"react-redux": "^5.0.4",
"react-responsive": "^1.2.7",
"react-router": "^2.0.0-rc5",
"react-router-dom": "^4.0.0",
"react-sizeme": "^2.3.1",
"react-tap-event-plugin": "^2.0.1",
"redux": "^3.6.0",
"redux-form": "^6.6.3",
"redux-promise": "^0.5.3",
"rimraf": "2.5.2",
"serve-favicon": "^2.3.0",
"style-loader": "^0.16.0",
"transfer-webpack-plugin": "^0.1.4",
"webpack": "^1.13.3"
}
}
buildHtml script :
import fs from 'fs';
import cheerio from 'cheerio';
import colors from 'colors';
/*eslint-disable no-console */
console.log("buildHTML.js start");
fs.readFile('src/index.html', 'utf8', (err, markup) => {
if (err) {
return console.log(err);
}
const $ = cheerio.load(markup);
$('head').prepend('');
fs.writeFile('public/index.html', $.html(), 'utf8', function (err) {
if (err) {
return console.log(err);
}
console.log('index.html written to /public'.green);
});
});
And then build.js
/*eslint-disable no-console */
import webpack from 'webpack';
import webpackConfig from '../webpack-production.config';
import colors from 'colors';
import ncp from 'ncp';
process.env.NODE_ENV = 'production';
console.log("build.js start");
//Static files to import in /public (images/css)
var source = [["src/images","public/images"],["src/css","public/css"]];
function copyStaticFiles(path){
ncp(path[0], path[1], function (err) {
if (err) {
return console.error(err);
}})
}
console.log('Generating minified bundle for production via Webpack...'.blue);
webpack(webpackConfig).run((err, stats) => {
if (err) { // so a fatal error occurred. Stop here.
console.log(err.bold.red);
return 1;
}
const jsonStats = stats.toJson();
if (jsonStats.hasErrors) {
return jsonStats.errors.map(error => console.log(error.red));
}
if (jsonStats.hasWarnings) {
console.log('Webpack generated the following warnings: '.bold.yellow);
jsonStats.warnings.map(warning => console.log(warning.yellow));
}
console.log(`Webpack stats: ${stats}`);
source.forEach(copyStaticFiles);
console.log('Your app has been compiled in production mode and written to /public.'.green);
return 0;
});
I don't even know where to start and i can't find any documentation about this kind of errors.
I can provide more informations if needed.
Thanks for reading me
Ok so i dont have a object with a HardwareKeyboardArrowDown so i went looking in my dependencies and i found that it came from the matérial-ui dependency.
I forced the version 17.4 in my package.json and it worked !
The message gave you the name of the function (component) that returns the invalid object. HardwareKeyboardArrowDown.
So you should look at the return of its render function and make sure you return a valid React element (or null)
That means no undefined, array etc..
Well, Im having a big problem, I have a front-end only react that send request to a ruby on rails api, we use redux, babel and webpack. My problem is, I cant make this react project work on Heroku.
This is a 503 response error from heroku.
Package.json:
{
"name": "real-networking-ui",
"version": "1.0.0",
"description": "Real Netoworking UI",
"main": "index.js",
"scripts": {
"start": "node -r babel-register ./node_modules/webpack-dev-server/bin/webpack-dev-server --config ./webpack.config.dev.js --progress --profile --colors",
"build": "node -r babel-register ./node_modules/webpack/bin/webpack --config ./webpack.config.prod --progress --profile --colors",
"lint": "eslint app test *.js"
},
"engines": {
"node": "6.6.0"
},
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^6.3.6",
"babel-core": "^6.10.4",
"babel-eslint": "^6.1.0",
"babel-loader": "^6.2.4",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-lodash": "^3.2.11",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-remove-console": "^6.8.0",
"babel-plugin-transform-remove-debugger": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-react-optimize": "^1.0.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"classnames": "^2.2.5",
"css-loader": "^0.23.1",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-import-resolver-webpack": "^0.3.2",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^1.10.0",
"eslint-plugin-jsx-a11y": "^1.5.3",
"eslint-plugin-react": "^5.2.2",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.21.0",
"json-loader": "^0.5.4",
"postcss-css-variables": "^0.5.1",
"postcss-loader": "^0.9.1",
"postcss-mixins": "^5.0.0",
"postcss-nested": "^1.0.0",
"postcss-partial-import": "^1.3.0",
"react-transform-hmr": "^1.0.4",
"style-loader": "^0.13.1",
"svg-react": "^1.0.9",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"axios": "^0.15.3",
"core-js": "^2.4.1",
"css-loader": "^0.23.1",
"lodash": "^4.17.2",
"moment": "^2.17.1",
"node-sass": "^3.13.0",
"react": "^15.1.0",
"react-dom": "^15.1.0",
"react-hot-loader": "^3.0.0-beta.6",
"react-maskedinput": "^3.3.1",
"react-modal": "^1.6.4",
"react-redux": "^4.4.5",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.5",
"react-select": "^1.0.0-rc.2",
"react-select-box": "^3.0.1",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"svg-react": "^1.0.9",
"validator": "^6.2.0",
"whatwg-fetch": "^2.0.1"
},
"eslintConfig": {
"extends": "react-app"
},
"babel": {
"presets": [
"react-app"
]
}
}
webpack.config.base:
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
export default {
entry: './app/app.js',
output: {
path: './app/App/dist',
filename: '/bundle.js',
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.svg$/,
loader: 'babel?presets[]=es2015,presets[]=react!svg-react',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './app/App/index.html',
}),
new ExtractTextPlugin('/app/App/css/default.css', {
allChunks: true,
}),
],
};
webpack.config.dev:
import webpack from 'webpack';
import baseConfig from './webpack.config.base';
const config = {
...baseConfig,
debug: true,
devtool: 'cheap-module-eval-source-map',
plugins: [
...baseConfig.plugins,
new webpack.HotModuleReplacementPlugin(),
],
devServer: {
colors: true,
historyApiFallback: true,
inline: true,
hot: true,
},
};
export default config;
webpack.config.prod.js:
import webpack from 'webpack';
import baseConfig from './webpack.config.base';
const config = {
...baseConfig,
plugins: [
...baseConfig.plugins,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false,
},
}),
],
};
export default config;
Procfile:
web: npm start
If you need more information about that tell me that I edit it.
Thank you for the help.
The heroku default configuration is to cache the dependencies in node_modules and set production environment to true.
Caching node_modules prevents additional modules from getting installed.
Production Environment prevents devDependencies in package.json from getting installed.
Refer to this link to solve the above problems
Also, webpack-dev-server doesn't work in Heroku, so it's better to create a small web server (Personally I like Express server) to serve the dist folder and then deploy the app.
Additionally, If you are still facing the problem, try running heroku logs --tail and paste the logs here.
My take on this is the devDependencies should be re-installed under dependencies. Under similar circumstances I had the error screen when trying to deploy on Heroku. The devDependencies are ignored and whenever your code asks for them Heroku alarms.