several instance of styled-component in node modules - reactjs

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.

Related

Error on type Props in react flow, converting create-react app to webpack

I am trying to convert a create-react app to a webpack app. The context behind this is that I originally have a app that was made using create-react. I wanted to run that project using webpack. I took an app that I had that was running on webpack, and then I delete all its source files, replacing the with the source files from the create react app. After that, I took package.json dependencies and moved them over from the package.json of the create-react app. I think perhaps I need some extra configuration in webpack to handle flow. I need help in troubleshooting. I get this type of error:
ERROR in ./src/js/constants/Routes.jsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token, expected ";" (7:5)
5 | import { reduxConnect } from '../hoc';
6 |
> 7 | type Props = {
This is my webpack.config.js:
const path = require('path');
const config = {
entry: __dirname + '/src/js/index.js',
output: {
path: __dirname + '/grails-app/assets/javascripts',
publicPath: '/assets/',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
resolve: {
extensions: [
'.js',
'.jsx'
]
}
};
module.exports = config;
This is my .babelrc
"presets": [
"#babel/preset-env",
"#babel/preset-react"
]
}
package.json (I run in prod mode so ignore devDependencies):
{
"name": "KahuDealerWeb",
"version": "1.0.0",
"description": "Vehicle Finance 3.0 ====================",
"main": "index.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"watch": "webpack --watch --colors --progress",
"bundle": "webpack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ProconGPS/KahuDealerWeb.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/ProconGPS/KahuDealerWeb/issues"
},
"homepage": "https://github.com/ProconGPS/KahuDealerWeb#readme",
"dependencies": {
"#babel/core": "^7.0.1",
"#babel/preset-env": "^7.0.0",
"#babel/preset-flow": "^7.10.1",
"#babel/preset-react": "^7.0.0",
"#material-ui/core": "^4.10.1",
"#material-ui/icons": "^4.9.1",
"axios": "^0.19.0",
"babel-loader": "^8.0.2",
"core-js": "^3.1.3",
"css-loader": "^3.5.3",
"lodash": "^4.17.11",
"material-ui-icons": "^1.0.0-beta.36",
"node-sass": "^4.10.0",
"react": "^16.13.1",
"react-cookies": "^0.1.0",
"react-dom": "^16.13.1",
"react-modal": "^3.11.1",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"react-select": "^2.2.0",
"react-to-print": "^2.5.1",
"recharts": "^1.8.5",
"redux": "^3.7.2",
"redux-observable": "^0.18.0",
"rxjs": "^5.5.6",
"rxjs-compat": "^6.3.3",
"style-loader": "^1.2.1",
"webpack": "^4.18.1",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.1.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
}
}
Flow syntax is not real JS. so things like type Props will fall apart when transpiling or bundling. You need to add a babel plugin/preset to handle these cases.
This is what you're looking to add:
https://babeljs.io/docs/en/babel-preset-flow
But specifically,
Install #babel/preset-flow with either yarn or npm
Then in your .babelrc update your config to add the new preset
{
"presets": [
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-flow"
]
}

How to install React on this project

I got this starting point app that was given to me, and I have to add react to it.
Its a basic node application with this sctructure:
MyProject
src
scripts
index.js
styles
index.scss
index.html
webpack
webpack.common.js
webpack.config.dev.js
webpack.config.prod.js
.babelrc
And I also got this package.json:
{
"name": "frontend-assessment-test",
"version": "1.0.0",
"description": "A frontend assessment test for our new pirates, which are willing to come on board.",
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config webpack/webpack.config.prod.js --colors",
"start": "webpack-dev-server --open --config webpack/webpack.config.dev.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/holidaypirates/frontend-assessment-test"
},
"author": "HolidayPirates",
"license": "MIT",
"bugs": {
"url": "https://github.com/holidaypirates/frontend-assessment-test/issues"
},
"devDependencies": {
"#babel/core": "^7.6.4",
"#babel/plugin-proposal-class-properties": "^7.5.5",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.6.3",
"babel-loader": "^8.0.6",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.0.4",
"cross-env": "^6.0.3",
"css-loader": "^3.2.0",
"eslint": "^6.5.1",
"eslint-loader": "^3.0.2",
"file-loader": "^4.2.0",
"html-webpack-plugin": "^4.0.0-beta.8",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.13.0",
"sass-loader": "^8.0.0",
"style-loader": "^1.0.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.9.0",
"webpack-merge": "^4.2.2"
},
"dependencies": {
"#babel/polyfill": "^7.6.0",
"core-js": "^3.3.3"
}
}
The babel file webpack.common.js has this configuration:
module.exports = {
entry: {
app: Path.resolve(__dirname, '../src/scripts/index.js')
},
output: {
path: Path.join(__dirname, '../build'),
filename: 'js/[name].js'
},
optimization: {
splitChunks: {
chunks: 'all',
name: false
}
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin([
{ from: Path.resolve(__dirname, '../public'), to: 'public' }
]),
new HtmlWebpackPlugin({
template: Path.resolve(__dirname, '../src/index.html')
})
],
resolve: {
alias: {
'~': Path.resolve(__dirname, '../src')
}
},
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
},
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
},
]
}
};
So because I saw threre is babel and style loader added to the webpack, if I would just install react and react-dom I could then start using react, if I would, in the index.js file import react and try to render a basic component.
But i get an error that Module build failed (from ./node_modules/babel-loader/lib/index.js):
Any idea what should I change in webpack config or which other package other than react
and react-dom in order to use react in index.js?
Thanks.
This code base will not support react js. Babel is used to converted the non understandable JS parts(mostly es6 or more) to es5. Simple babel configuration will not work in your case, every library has their own way of syntax.
For example, in order to use the react you should be installing babel-preset-react which is mandatory for react.
The above mentioned will understand the jsx and react functionalities and converts to es5.
Install react first, see the hello world is working then try to add your node.js project into that react, try to add small chunk continuously and see the result
My personal opinion if possible, keep UI(react) and backend(node) separate

Deploy React-Redux webpack on heroku

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.

Can't Get Bootstrap v4 Working in react-slingshot

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

"The use of a keyword for an identifier is invalid" error when loading React app that uses Webpack in Windows Edge 13

I'm totally stumped on this error. I've been investigating this for days to no avail.
It is a fairly complex web app that uses React, Webpack and Babel to run. The error I get in the Edge console seems to related to Webpack, so I've added a couple of polyfills but that didn't change anything.
I haven't seen anyone else encountering this error, which I find surprising. I've updated all node packages but that didn't fix it either.
Here is the package.json, I currently have:
{
"name": "some-app",
"private": true,
"dependencies": {
"babel-core": "^5.8.22",
"babel-loader": "^5.3.2",
"babel-polyfill": "^6.5.0",
"babel-relay-plugin": "^0.3.0",
"chart.js": "^1.0.2",
"css-loader": "^0.22.0",
"es5-shim": "^4.5.7",
"graphiql": "0.3.1",
"history": "1.13.1",
"isomorphic-fetch": "^2.1.1",
"jsxstyle": "^0.0.17",
"mockdate": "1.0.3",
"moment": "^2.10.2",
"react": "^0.14.0",
"react-addons-shallow-compare": "^0.14.0",
"react-chartjs": "^0.6.0",
"react-dom": "^0.14.0",
"react-loader": "^2.0.0",
"react-relay": "^0.4.0",
"react-router": "1.0.0-rc3",
"react-router-relay": "^0.7.0",
"style-loader": "^0.12.3",
"superagent": "^1.2.0",
"underscore": "^1.8.3",
"webpack": "^1.12.13"
},
"devDependencies": {
"babel-eslint": "^3.1.30",
"babel-jest": "^5.3.0",
"classnames": "^2.2.3",
"eslint": "^0.23",
"eslint-config-airbnb": "0.0.7",
"eslint-plugin-react": "^3.2.2",
"jest-cli": "^0.5.0",
"react-addons-test-utils": "^0.14.0-beta3"
},
"scripts": {
"test": "node node_modules/.bin/jest --verbose --runInBand",
"build": "node node_modules/.bin/webpack",
"postinstall": "npm run build"
},
"jest": {
"rootDir": "",
"scriptPreprocessor": "node_modules/babel-jest",
"preprocessorIgnorePatterns": [
"<rootDir>/node_modules/"
],
"testPathDirs": [
"<rootDir>/src/"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react/",
"<rootDir>/node_modules/react-dom/",
"<rootDir>/node_modules/react-addons-test-utils/",
"<rootDir>/node_modules/react-relay/",
"<rootDir>/node_modules/react-router/",
"<rootDir>/node_modules/react-sticky/",
"<rootDir>/node_modules/jsxstyle/",
"<rootDir>/node_modules/underscore/",
"<rootDir>/src/__tests__/",
"<rootDir>/src/components/delay/",
"<rootDir>/src/mutations/",
"<rootDir>/src/components/react-wrapper"
]
}
}
Can anyone see anything obvious as to why the app wouldn't run at all in Edge 13? The error I get in the console is:
Anything that gets me on the right track, I'd appreciate!
Edit
My webpack.config looks like this:
module.exports = {
entry: {
academy: "./src/app.js"
},
output: {
filename: "../website/app/assets/javascripts/academy/[name].js"
},
module: {
loaders: [
{ test: /\.js$/, loaders: ["babel-loader"], exclude: /node_modules/ },
{ test: /\.css$/, loader: "style-loader!css-loader" }
]
},
resolve: {
extensions: ["", ".js"]
},
devtool: process.env.NODE_ENV !== "production" ? "eval-source-map" : null
};

Resources