I am using react-slingshot to build my React applications, and I am trying to integrate Bootstrap v4 into it and not having any luck with getting the JavaScript working.
So far, I have a package.json file that looks like the following:
{
"name": "react-slingshot",
"version": "5.0.0",
"description": "Starter kit for creating apps with React and Redux",
"engines": {
"npm": ">=3"
},
"scripts": {
"preinstall": "node tools/nodeVersionCheck.js",
"setup": "node tools/setup/setupMessage.js && npm install && node tools/setup/setup.js",
"remove-demo": "babel-node tools/removeDemo.js",
"start-message": "babel-node tools/startMessage.js",
"prestart": "npm-run-all --parallel start-message remove-dist",
"start": "npm-run-all --parallel test:watch open:src lint:watch",
"open:src": "babel-node tools/srcServer.js",
"open:dist": "babel-node tools/distServer.js",
"lint": "esw webpack.config.* src tools --color",
"lint:watch": "npm run lint -- --watch",
"clean-dist": "npm run remove-dist && mkdir dist",
"remove-dist": "rimraf ./dist",
"prebuild": "npm run clean-dist && npm run lint && npm run test",
"build": "babel-node tools/build.js && npm run open:dist",
"test": "mocha tools/testSetup.js \"src/**/*.spec.js\" --reporter progress",
"test:cover": "babel-node node_modules/isparta/bin/isparta cover --root src --report html node_modules/mocha/bin/_mocha -- --require ./tools/testSetup.js \"src/**/*.spec.js\" --reporter progress",
"test:cover:travis": "babel-node node_modules/isparta/bin/isparta cover --root src --report lcovonly _mocha -- --require ./tools/testSetup.js \"src/**/*.spec.js\" && cat ./coverage/lcov.info | node_modules/coveralls/bin/coveralls.js",
"test:watch": "npm run test -- --watch",
"open:cover": "npm run test:cover && open coverage/index.html"
},
"author": "Cory House",
"license": "MIT",
"dependencies": {
"bootstrap": "4.0.0-alpha.4",
"bootstrap-loader": "2.0.0-beta.12",
"imports-loader": "0.6.5",
"jquery": "3.1.1",
"moment": "2.15.1",
"object-assign": "4.1.0",
"react": "15.3.1",
"react-addons-transition-group": "15.3.2",
"react-dom": "15.3.1",
"react-redux": "4.4.5",
"react-router": "2.7.0",
"react-router-redux": "4.0.5",
"reactstrap": "3.3.2",
"redux": "3.5.2",
"redux-thunk": "2.1.0",
"tether": "1.3.7"
},
"devDependencies": {
"autoprefixer": "6.4.0",
"babel-cli": "6.14.0",
"babel-core": "6.14.0",
"babel-loader": "6.2.5",
"babel-plugin-react-display-name": "2.0.0",
"babel-plugin-transform-react-constant-elements": "6.9.1",
"babel-plugin-transform-react-remove-prop-types": "0.2.9",
"babel-preset-latest": "6.14.0",
"babel-preset-react": "6.11.1",
"babel-preset-react-hmre": "1.1.1",
"babel-preset-stage-1": "6.13.0",
"babel-register": "6.14.0",
"bootstrap": "4.0.0-alpha.4",
"browser-sync": "2.14.0",
"chai": "3.5.0",
"chalk": "1.1.3",
"connect-history-api-fallback": "1.3.0",
"coveralls": "2.11.12",
"cross-env": "2.0.1",
"css-loader": "0.24.0",
"enzyme": "2.4.1",
"eslint": "3.4.0",
"eslint-plugin-import": "1.14.0",
"eslint-plugin-jsx-a11y": "2.2.0",
"eslint-plugin-react": "6.2.0",
"eslint-watch": "2.1.14",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.9.0",
"html-webpack-plugin": "2.22.0",
"isparta": "4.0.0",
"mocha": "3.0.2",
"mockdate": "1.0.4",
"node-sass": "3.8.0",
"npm-run-all": "3.0.0",
"open": "0.0.5",
"postcss-loader": "0.11.0",
"prompt": "1.0.0",
"react-addons-test-utils": "15.3.1",
"redux-immutable-state-invariant": "1.2.3",
"replace": "0.3.0",
"resolve-url-loader": "1.6.0",
"rimraf": "2.5.4",
"sass-loader": "4.0.0",
"sinon": "1.17.5",
"sinon-chai": "2.8.0",
"style-loader": "0.13.1",
"url-loader": "0.5.7",
"webpack": "1.13.2",
"webpack-dev-middleware": "1.6.1",
"webpack-hot-middleware": "2.12.2",
"webpack-md5-hash": "0.0.5"
},
"keywords": [
"react",
"reactjs",
"react-router",
"hot",
"reload",
"hmr",
"live",
"edit",
"webpack",
"redux",
"flux",
"boilerplate",
"starter"
],
"repository": {
"type": "git",
"url": "https://github.com/coryhouse/react-slingshot"
}
}
I have a webpack file that looks like:
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import autoprefixer from 'autoprefixer';
import path from 'path';
export default {
resolve: {
extensions: ['', '.js', '.jsx']
},
debug: true,
devtool: 'eval-source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool
noInfo: true, // set to false to see a list of every file being bundled.
entry: [
'bootstrap-loader',
'./src/webpack-public-path',
'webpack-hot-middleware/client?reload=true',
path.resolve(__dirname, 'src/index.js') // Defining path seems necessary for this to work consistently on Windows machines.
],
target: 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test
output: {
path: path.resolve(__dirname, 'dist'), // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
Tether: "tether",
"window.Tether": "tether",
Tooltip: "exports?Tooltip!bootstrap/js/dist/tooltip",
Alert: "exports?Alert!bootstrap/js/dist/alert",
Button: "exports?Button!bootstrap/js/dist/button",
Carousel: "exports?Carousel!bootstrap/js/dist/carousel",
Collapse: "exports?Collapse!bootstrap/js/dist/collapse",
Dropdown: "exports?Dropdown!bootstrap/js/dist/dropdown",
Modal: "exports?Modal!bootstrap/js/dist/modal",
Popover: "exports?Popover!bootstrap/js/dist/popover",
Scrollspy: "exports?Scrollspy!bootstrap/js/dist/scrollspy",
Tab: "exports?Tab!bootstrap/js/dist/tab",
Util: "exports?Util!bootstrap/js/dist/util",
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'), // Tells React to build in either dev or prod modes. https://facebook.github.io/react/downloads.html (See bottom)
__DEV__: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({ // Create HTML file that includes references to bundled CSS and JS.
template: 'src/index.ejs',
minify: {
removeComments: true,
collapseWhitespace: true
},
inject: true
})
],
module: {
loaders: [
{ test: /bootstrap.+\.(jsx|js)$/, loader: 'imports?jQuery=jquery,$=jquery,this=>window' },
{test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel']},
{test: /\.eot(\?v=\d+.\d+.\d+)?$/, loader: 'file'},
{test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url?limit=10000&mimetype=application/font-woff"},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
{test: /\.(jpe?g|png|gif)$/i, loader: 'file?name=[name].[ext]'},
{test: /\.ico$/, loader: 'file?name=[name].[ext]'},
{test: /(\.css|\.scss)$/, loaders: ['style', 'css?sourceMap', 'postcss', 'sass?sourceMap']},
]
},
postcss: ()=> [autoprefixer]
};
And I am getting the following error:
ERROR in ./~/bootstrap-loader/lib/bootstrap.loader.js!./~/bootstrap-loader/no-op.js
Module build failed: Error:
Could not find bootstrap version: '3'. Did you install it?
The package is 'bootstrap' for bootstrap v4 and 'bootstrap-sass' for v3.
at Object.module.exports.pitch (/Users/ryannealmes/sites/work/andromeda/node_modules/bootstrap-loader/lib/bootstrap.loader.js:143:11)
# ./~/bootstrap-loader/loader.js 6:17-61
Child html-webpack-plugin for "index.html":
I have Googled around and found many answers around this, but none of them work. Can anyone point me in the direction I should be looking to get Bootstrap v4 JavaScript working for react-slingshot?
Are you attempting to use bootstrap v3 or v4? You have v4 installed if you are looking to use that you need to additionally have a .bootstraprc in your project root that has a minimum "bootstrapVersion": 3.
Additionally, I would move down the bootstrap-loader in your entry below the ./src/webpack-public-path as this file fixes issues relative paths to icon fonts. This was mostly an issue with bootstrap 3, but may have ill effects if not first in the list.
source
Related
I have added laravel-mix in my `React application. Below is my code
My webpack.mix.js looks like the following
let mix = require('laravel-mix');
mix.js('src/scripts.ts', '/dist/')
.sass('src/styles.scss', '/dist/')
.options({
processCssUrls: false,
})
.disableSuccessNotifications()
.webpackConfig({
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx', '.vue', '.ts', '.tsx'],
},
});
My package.json scripts and dependeinces looks like the following:
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/preset-react": "^7.18.6",
"#types/node-polyglot": "^2.4.2",
"#types/react": "^17.0.14",
"#types/react-dom": "^17.0.9",
"#typescript-eslint/eslint-plugin": "^4.28.4",
"#typescript-eslint/parser": "^4.28.4",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"laravel-mix": "^6.0.25",
"prettier": "^2.3.2",
"sass": "^1.35.2",
"sass-loader": "^12.1.0",
"stylelint": "^13.13.1",
"stylelint-config-idiomatic-css": "^1.1.0",
"stylelint-config-sass-guidelines": "^8.0.0",
"stylelint-config-standard": "^22.0.0",
"ts-loader": "^9.2.3",
"typescript": "^4.3.5"
},
I am able to successfully compile the application using npm run dev I also get notifications on my desktop Laravel Mix Build Successful, but when I run php artisan serve I get the below error
Could not open input file: artisan
Anyone has gone through this problem? I am in the root directory when I run this command.
I have recently updated my react-native-web project to use a more recent react native version to use a more recent expo version.
with the help of npm I have now a fully functional updated code running on ios and android.
However I have still difficulties running it on webpack with different problems related (to the best of my understanding) to a webpack that needs to be updated as well to a higher version (2 -> 3or4).
in this process I have found difficulties matching the right webpack version to the right dev-server and cli.
here is my package.json
"devDependencies": {
"babel-loader": "^7.1.2",
"babel-plugin-expo-web": "^0.0.5",
"babel-plugin-react-native-web": "0.9.9",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-imports": "1.4.1",
"babel-plugin-transform-runtime": "6.23.0",
"css-loader": "0.28.7",
"docz": "^0.12.16",
"eslint-plugin-react": "^7.10.0",
"file-loader": "^1.1.7",
"gh-pages": "^1.2.0",
"jest-expo": "^30.0.0",
"react-native-scripts": "^2.0.1",
"react-styleguidist": "^8.0.6",
"react-test-renderer": "16.4.1",
"style-loader": "^0.19.0",
"sw-precache-webpack-plugin": "^0.11.5",
"webpack-cli": "^3.1.2",
"webpack-manifest-plugin": "^2.0.4"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry-web.js",
"scripts": {
"start": "expo start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest",
"clean": "rm -rf node_modules && yarn cache clean && npm cache clean --force",
"make": "yarn",
"docu:dev": "docz dev",
"docu:build": "docz build",
"web": "webpack-dev-server -d --config ./webpack.config.js --env dev --inline --hot --colors --content-base app/ --history-api-fallback",
"build:dev": "NODE_ENV=production webpack --env dev --config ./webpack.config.js",
"build:prod": "NODE_ENV=production webpack --env prod --config ./webpack.config.js"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"#sentry/browser": "^4.4.1",
"#sentry/cli": "^1.31.0",
"audit": "0.0.6",
"babel-plugin-transform-remove-console": "^6.9.4",
"es6-symbol": "^3.1.1",
"expo": "^30.0.0",
"expo-analytics": "1.0.7",
"expo-firebase-crashlytics": "1.0.0",
"expo-web": "0.0.14",
"firebase": "^5.0.4",
"jsc-android": "^224109.1.0",
"mobx": "4",
"mobx-react": "5.1.0",
"npm": "^6.5.0",
"prop-types": "^15.6.2",
"query-string": "^6.2.0",
"react": "16.5.1",
"react-art": "16.5.1",
"react-css-blur": "^1.1.1",
"react-dom": "^16.5.1",
"react-markdown": "^4.0.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz",
"react-native-blur": "^3.2.2",
"react-native-camera-roll-picker": "^1.2.3",
"react-native-dialog": "^5.4.0",
"react-native-simple-markdown": "^1.1.0",
"react-native-web": "0.9.0",
"react-native-web-svg": "1.0.0",
"react-navigation": "~2.3.1",
"sentry-expo": "^1.11.0",
"sweetalert": "2.1.2",
"uglifyjs-webpack-plugin": "1",
"webpack": "^4.0.0",
"webpack-dev-server": "^3.1.10",
"ws": "^6.0.0"
}
And now I would like to know and understand what I should change web-wise to make my yarn run web script work again, basically.
//web/webpack.config.js
const path = require("path");
const webpack = require("webpack");
const appDirectory = path.resolve(__dirname, "./");
// Many OSS React Native packages are not compiled to ES5 before being
// published. If you depend on uncompiled packages they may cause webpack build
// errors. To fix this webpack can be configured to compile to the necessary
// 'node_module'.
const babelLoaderConfiguration = {
test: /\.js$/,
// Add every directory that needs to be compiled by Babel during the build.
include: [
path.resolve(appDirectory, "src"),
path.resolve(appDirectory, "node_modules/react-navigation"),
path.resolve(appDirectory, "node_modules/react-native-tab-view"),
path.resolve(appDirectory, "node_modules/react-native-paper"),
path.resolve(appDirectory, "node_modules/react-native-vector-icons"),
path.resolve(appDirectory, "node_modules/react-native-safe-area-view"),
path.resolve(appDirectory, "node_modules/#expo/samples"),
path.resolve(appDirectory, "node_modules/#expo/vector-icons"),
path.resolve(appDirectory, "node_modules/react-native-platform-touchable"),
],
use: {
loader: "babel-loader",
options: {
// cacheDirectory: false,
babelrc: false,
sourceMaps: true,
// minimize: false,
// Babel configuration (or use .babelrc)
// This aliases 'react-native' to 'react-native-web' and includes only
// the modules needed by the app.
plugins: [
"expo-web",
"react-native-web",
"transform-decorators-legacy",
["transform-runtime", { helpers: true, polyfill: true, regenerator: true }],
],
// The 'react-native' preset is recommended to match React Native's packager
presets: ["react-native"],
},
},
};
// This is needed for loading css
const cssLoaderConfiguration = {
test: /\.css$/,
use: ["style-loader", "css-loader"],
};
const imageLoaderConfiguration = {
test: /\.(gif|jpe?g|png|svg)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[ext]",
},
},
};
const ttfLoaderConfiguration = {
test: /\.ttf$/,
use: [
{
loader: "file-loader",
options: {
name: "./fonts/[hash].[ext]",
},
},
],
include: [
path.resolve(appDirectory, "./src/assets/fonts"),
path.resolve(appDirectory, "node_modules/react-native-vector-icons"),
],
};
module.exports = {
// your web-specific entry file
entry: path.resolve(appDirectory, "src/index.js"),
devtool: "#eval-source-map",
// mode: 'development',
// configures where the build ends up
output: {
filename: "bundle.js",
publicPath: "/assets/",
path: path.resolve(appDirectory, "./app/assets"),
},
module: {
rules: [
babelLoaderConfiguration,
cssLoaderConfiguration,
imageLoaderConfiguration,
ttfLoaderConfiguration,
],
},
plugins: [
// process.env.NODE_ENV === 'production' must be true for production
// builds to eliminate development checks and reduce build size. You may
// wish to include additional optimizations.
// https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/206#issuecomment-358015555
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development"), //JSON.stringify("production")
__DEV__: process.env.NODE_ENV === "production" || true,
}),
],
resolve: {
// If you're working on a multi-platform React Native app, web-specific
// module implementations should be written in files using the extension
// '.web.js'.
symlinks: false,
extensions: [".web.js", ".js", ".json"],
alias: {
"./assets/images/expo-icon.png": "./assets/images/expo-icon#2x.png",
"./assets/images/slack-icon.png": "./assets/images/slack-icon#2x.png",
"#expo/vector-icons": "expo-web",
expo: "expo-web",
"react-native$": "react-native-web",
'react-native-svg$': 'react-native-web-svg',
"babel-runtime/regenerator": require.resolve("babel-runtime/regenerator"),
},
},
};
Thanks to all.
I'm unable to generate the bundle.js file.
This is my webpack.config.js.
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
This is my package.json
{
"name": "redux-react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "4.3.0",
"react-router": "^2.0.1",
"redux": "^3.0.4"
}
}
The main aim is to build a production-ready app hence how do I configure my webpack to generate the bundle.js file. Also is it necessary to have seperate webpack.config for dev and production server?
webpack-dev-server is for development purpose. This will not put your bundle.js in your work directory, it will compile your files in-memory.
I can see from your package scripts that you are running a webpack-dev-server to build the code
I updated my project's react version from 15.3.1 to 16.2.0. I'm getting the following runtime error message.
Uncaught TypeError: Cannot read property 'bool' of undefined
at eval (Transition.js?0efa:259)
at Object.<anonymous> (bundle.js:4059)
at __webpack_require__ (bundle.js:1337)
at fn (bundle.js:744)
at eval (398:19)
at Object.<anonymous> (bundle.js:3348)
at __webpack_require__ (bundle.js:1337)
at fn (bundle.js:744)
at eval (99:30)
at Object.<anonymous> (bundle.js:1647)
I did the update gradually and the app worked well in 15.6.2. The error started appearing after I updated it to 16.0.0. I updated it to 16.2.0 hoping it would resolve it. But no luck. My webpack.config.js and package.json is below
package.json
{
"name": "myProject",
"version": "28.0.0",
"description": "New front end",
"main": "main.js",
"scripts": {
"test": "jest",
"test-coverage": "jest --coverage",
"dev": "webpack --config webpack.config.js -d --watch",
"build": "webpack --config ./webpack.config.production.js --progress -p",
"start": "webpack-dev-server --config ./webpack.config.js --hot"
},
"repository": "",
"author": "Sarani",
"license": "BSD",
"dependencies": {
"babel": "~6.5.2",
"babel-core": "~6.13.2",
"babel-loader": "~6.2.4",
"babel-polyfill": "~6.16.0",
"babel-preset-es2015": "~6.13.2",
"babel-preset-react": "~6.11.1",
"create-react-class": "^15.6.3",
"css-loader": "~0.18.0",
"file-loader": "~0.9.0",
"isomorphic-fetch": "~2.2.1",
"json-loader": "~0.5.4",
"less": "~2.7.1",
"less-loader": "~2.2.3",
"moment-range": "~3.0.3",
"moment-timezone": "~0.5.13",
"prop-types": "^15.6.0",
"react": "^16.0.0",
"react-bootstrap": "~0.30.2",
"react-dom": "^16.0.0",
"react-redux": "~4.4.5",
"react-router": "^3.2.0",
"redux": "~3.5.2",
"redux-immutable-state-invariant": "~1.2.3",
"redux-thunk": "~2.1.0",
"style-loader": "~0.13.1",
"url-loader": "~0.5.7",
"webpack": "^3.10.0"
},
"devDependencies": {
"babel-eslint": "~6.1.2",
"babel-jest": "~14.1.0",
"eslint": "~3.5.0",
"eslint-config-airbnb": "~11.1.0",
"eslint-loader": "~1.5.0",
"eslint-plugin-import": "~1.15.0",
"eslint-plugin-jsx-a11y": "~2.2.2",
"eslint-plugin-react": "~6.2.2",
"gulp": "~3.9.1",
"gulp-csslint": "~1.0.0",
"gulp-watch": "~4.3.10",
"jest": "~14.1.0",
"jest-cli": "~14.1.0",
"react-a11y": "~0.3.3",
"react-addons-test-utils": "~15.3.2",
"react-test-renderer": "~15.3.1",
"redux-mock-store": "~1.2.1",
"webpack-dev-server": "~1.14.1"
},
"jest": {
"automock": false,
"moduleNameMapper": {
"^.+\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"^.+\\.(gif|ttf|eot|svg)$": "<rootDir>/__mocks__/fileMock.js",
"^config$": "<rootDir>/__mocks__/configMock.js"
},
"moduleFileExtensions": [
"js",
"jsx"
]
}
}
webpack.config.js
var webpack = require('webpack');
var path = require('path');
module.exports = {
devtool: 'eval-source-map',
entry: {
bundle: ['babel-polyfill', './Main.js'],
bundleIntegrated: ['babel-polyfill', './MainIntegrated.js']
},
output: {
path: path.resolve(__dirname, '../assets/myProject'),
filename: '../assets/myProject/[name].js'
},
target: 'web',
devServer: {
inline: true,
port: 8080,
proxy: {
'/myct/**': {
target: 'http://localhost:9000',
secure: false,
changeOrigin: true
}
}
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin()
],
resolve: {
extensions: ['.js', '.jsx'],
alias: {
config: path.join(__dirname, 'config/config.dev')
}
},
module: {
rules: [
{
test: /.(js|jsx)$/,
enforce: 'pre',
exclude: /node_modules/,
use: [
{
loader: "eslint-loader",
}
],
},
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|__tests__)/,
loader: "babel-loader",
},
{
test: /\.css$/,
use: [
"style-loader",
"css-loader",
],
},
{
test: /\.less$/,
use: [
"style-loader",
"css-loader",
"less-loader",
],
},
{
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
use: [
{
loader: "file-loader?name=../assets/myProject/fonts/[name].[ext]",
},
],
},
]
}
}
Any ideas on how to fix this issue. Thanks in advance :)
I had the same issue.
If you run yarn info react-bootstrap peerDependencies, you will see the following:
{
react: '>=16.8.0',
'react-dom': '>=16.8.0'
}
So, make sure the versions are correct.
I've fixed it by running yarn add react#latest and also yarn add react-dom#latest. In addition, I set react-bootstrap to 0.32.4, as version 1.0.0 threw different errors.
"react": "^16.13.1",
"react-bootstrap": "0.32.4",
"react-dom": "^16.13.1",
Thank you all for your help. I managed to fix the issue by updating the following to latest versions. The solution can be found here
"react": "latest",
"react-dom": "latest",
"react-bootstrap": "latest",
"react-router-dom": "latest"
My webpack config can run in MacOS,but it is showing error on Windows.
webpack.config.js
var path = require("path");
var webpack = require("webpack");
var FileSystem = require("fs");
var argv = require('yargs').argv;
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'cheap-module-source-map',
entry: {
main: ['webpack/hot/dev-server','webpack-dev-server/client?http://localhost:8090',path.resolve(__dirname, 'app','index.jsx')],
vendor:['react', 'redux', 'amazeui-react','react-redux' ,'react-router']
},
output: {
path: path.resolve(__dirname, 'dist','app'),
publicPath: '/dist/app/',
filename: 'bundle.[hash].js',
chunkFilename: '[id].[hash].chunk.js',
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'),
new ExtractTextPlugin('[name]-[chunkhash].css', {allChunks: true}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('dev')
}
}),
new webpack.DefinePlugin({
'process.env.db_env': JSON.stringify(argv['db_env'] ? argv['db_env'] + '' : 'dev'),
}),
function() {
this.plugin("done", function(statsData) {
var stats = statsData.toJson();
var bundlejs,maincss;
var mains = stats.assetsByChunkName.main;
console.log(mains);
for (var i = 0; i < mains.length; i++) {
if (/^(bundle).+(js)$/.test(mains[i])) {
bundlejs = mains[i]
}
if (/^(main).+(css)$/.test(mains[i])) {
maincss = mains[i]
}
}
if (!stats.errors.length) {
var htmlFileName = "index.html";
var html = FileSystem.readFileSync(path.join('./resources/temp', htmlFileName), "utf8");
var htmlOutput = html.replace('bundle.js', bundlejs).replace('main.css', maincss);
FileSystem.writeFileSync(path.join('./', htmlFileName), htmlOutput);
}
});
}
],
module: {
loaders: [
{
test: /\.css$/,
loader: "style!css"
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style','css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!sass?outputStyle=expanded&sourceMap')
},
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel', // 'babel-loader' is also a legal name to reference
query: {
plugins: ['transform-runtime', 'add-module-exports', "transform-decorators-legacy"],
presets: ['react', 'es2015', 'stage-0']
}
},
{
test: /\.js$/,
loaders: [ 'babel' ],
exclude: /node_modules/,
include: __dirname
},
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=8192' }
]
},
externals: {
BMap:'BMap',
BMapLib:'BMapLib'
},
resolve: {
root:path.resolve(__dirname),
modulesDirectories: [
'app',
'node_modules'
],
extensions: ['', '.js', '.jsx','.scss','.css']
},
resolveLoader: {
root:path.resolve(__dirname,"node_modules"),
},
devServer: {
port: 8090,
hot: true,
host:"0.0.0.0",
historyApiFallback: {
index: 'index.html'
}
}
};
My directory structure is this:
+src
+app
+node_modules
+webpack.config.js
and everything is working fine on MacOS,but when I run it on Windows,I get an error:
Module not found: Error: Cannot resolve module 'css' in somefile.
The file just like this:
const style = require('./BuildingDetailContainer.scss');
and I'm sure that I have installed css-loader sass-loader style-loader
This is my package.json, I suspect it is caused by this file.Maybe because I don't add my loader to dependencies.
{
"name": "souban-website",
"version": "1.0.0",
"description": "souban website",
"author": "souban team",
"license": "UNLICENSED",
"private": true,
"engines": {
"node": ">=5.0.0",
"npm": "^3.0.0"
},
"scripts": {
"clean": "rm -rf dist",
"start": "npm run webpack-dev",
"deploy": "npm run test && npm run clean && npm run compile",
"webpack": "rm -rf dist && NODE_ENV=production webpack --display-error-details --colors --progress -p --config webpack.prod.config.js",
"webpack-dev": "webpack-dev-server --progress --colors --hot --inline",
"webpack-release": "rm -rf dist && NODE_ENV=production webpack --display-error-details --colors --progress -p --config webpack.rele.config.js --db_env production",
"webpack-dev-release": "rm -rf dist && NODE_ENV=production webpack --display-error-details --colors --progress -p --config webpack.rele.config.js --db_env dev"
},
"dependencies": {
"amazeui-react": "^1.0.1",
"babel-runtime": "^6.6.1",
"color": "^0.11.3",
"colormin": "^1.1.2",
"css-loader": "^0.24.0",
"extract-text-webpack-plugin": "^1.0.1",
"moment": "^2.12.0",
"node-sass": "^3.8.0",
"postcss-colormin": "^2.2.0",
"react": "^0.14.7",
"react-count-to": "^0.4.0",
"react-dom": "^0.14.6",
"react-motion": "^0.4.2",
"react-redux": "^4.0.6",
"react-router": "^2.4.0",
"redux": "^3.0.6",
"sass-loader": "^4.0.0",
"style-loader": "^0.13.1",
"webpack": "^1.12.12"
},
"devDependencies": {
"autobind-decorator": "^1.3.3",
"babel-core": "^6.4.5",
"babel-loader": "^6.2.1",
"babel-plugin-add-module-exports": "^0.1.4",
"babel-plugin-react-transform": "^2.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.6.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.5.0",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"isomorphic-fetch": "^2.2.1",
"jsx-loader": "^0.13.2",
"lodash": "^4.3.0",
"node-sass": "^3.6.0",
"radium": "^0.16.6",
"react-addons-css-transition-group": "^0.14.6",
"react-cookie": "^0.4.3",
"react-dom": "^0.14.5",
"react-hot-loader": "^1.3.0",
"react-modal": "^0.6.1",
"react-motion": "^0.4.1",
"redux-logger": "^2.3.1",
"redux-persist": "^1.5.5",
"redux-persist-crosstab": "^1.0.1",
"redux-thunk": "^1.0.3",
"sass-loader": "^3.2.0",
"scroll-behavior": "^0.3.0",
"style-loader": "^0.13.0",
"url-loader": "^0.5.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0",
"yargs": "^4.7.1"
}
}
I do work on windows and it was a nightmare to make things running smooth on it, everything worked fine on mac but not on windows, so If this is only wrong with Windows and Sass you might have to add the path manually to the sass loader.
The trick on Windows is here:
Display hidden files and folders.
Check the folder at 'user/appData', path should be: C:\Users\user\AppData\Roaming\npm
Add the enviroment variable to the Windows: NODE_PATH and point it to the nodeModules C:\Users\user\AppData\Roaming\npm\nodeModules
Run npm install -g
Close and reopen the terminal.
I'm using the sass loader 3.0, and in my webpack.config it's like this:
const path = require("path");
const srcPath = path.join(__dirname, 'src');
const sassLoaders = [
"css-loader",
"autoprefixer-loader?browsers=last 2 version",
"sass-loader?indentedSyntax=sass&includePaths[]=" + path.resolve(__dirname, "./src"),
];
I have the in my package.json for the loading:
"autoprefixer-loader": "3.1.0"
"sass-loader": "^3.0.0",
"style-loader": "0.12.4"
My resolve uses path.sep it is necessary in Windows as far as I reserached:
resolve: {
extensions: ["", ".js", ".scss"],
modulesDirectories: ["src", "node_modules"],
root: [__dirname + path.sep + 'scripts'],
}
As a heads up, for the loaders I use like this, and I noticed you don't have sass loaders in your modules:
{test: /\.scss$/, loaders: ["style", "css", "sass"]},
{test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader")},