As soon as I import styled-components (import styled from 'styled-components';) into my react app I get the following error:
Uncaught TypeError: __webpack_require__.i(...) is not a function
at Object.eval (styled-components.br…er.esm.js?60a8:1670)
at eval (318:2534)
at Object.<anonymous> (bundle.js:3892)
at __webpack_require__ (bundle.js:20)
at eval (app.js?fbdb:5)
at Object.<anonymous> (bundle.js:1609)
at __webpack_require__ (bundle.js:20)
at eval (index.js?c3ed:7)
at Object.<anonymous> (bundle.js:1967)
at __webpack_require__ (bundle.js:20)
(anonymous) # styled-components.br…er.esm.js?60a8:1670
(anonymous) # 318:2534
(anonymous) # bundle.js:3892
__webpack_require__ # bundle.js:20
(anonymous) # app.js?fbdb:5
(anonymous) # bundle.js:1609
__webpack_require__ # bundle.js:20
(anonymous) # index.js?c3ed:7
(anonymous) # bundle.js:1967
__webpack_require__ # bundle.js:20
(anonymous) # bundle.js:77
(anonymous) # bundle.js:80
My webpack.config file looks like this:
var path = require('path');
var LiveReloadPlugin = require('webpack-livereload-plugin');
module.exports = {
entry: './client/src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'client/src/public/dist')
},
context: __dirname,
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.json', '*']
},
module: {
rules: [{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: ['react', 'es2015', 'stage-1'],
sourceMap: true
}
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
},
plugins: [
new LiveReloadPlugin({appendScriptTag: true})
]
};
Any idea what could be causing this?
Here is my package.json:
{
"name": "cryptoApp",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"lint": "./node_modules/eslint/bin/eslint.js client/src",
"build-watch": "npm run build -- -w -d",
"start": "node server/index.js",
"start-watch": "nodemon server/index.js --watch server --watch db",
"dev": "cross-env NODE_ENV=development concurrently --kill-others --prefix \"[{name}]\" --names \"BUILD,SERVE\" -c \"bgBlack.bold.green,bgBlack.bold.red\" \"npm run build-watch\" \"npm run start-watch\""
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.16.2",
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.1",
"connect-session-sequelize": "^4.1.0",
"express": "^4.15.2",
"express-session": "^1.15.3",
"nodemon": "^1.11.0",
"passport": "^0.3.2",
"passport-google-oauth2": "^0.1.6",
"pg": "^6.2.4",
"pg-hstore": "^2.3.2",
"prop-types": "^15.6.2",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-redux": "^5.0.4",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"redux": "^3.6.0",
"redux-devtools-extension": "^2.13.0",
"redux-logger": "^3.0.1",
"redux-thunk": "^2.2.0",
"sequelize": "^4.4.0",
"styled-components": "^4.1.3",
"volleyball": "^1.4.1",
"webpack-livereload-plugin": "^0.11.0"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"concurrently": "^3.4.0",
"cross-env": "^5.0.1",
"css-loader": "^0.28.0",
"eslint": "^5.13.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"node-sass": "^4.5.2",
"sass-loader": "^6.0.3",
"style-loader": "^0.16.1",
"webpack": "^2.4.1"
}
}
Look at the following line in the error traceback:
at Object.eval (styled-components.br…er.esm.js?60a8:1670)
Lets take a look at that line in node_modules/styled-components/dist/styled-components.browser.esm.js. You'll see the following:
var ThemeContext = createContext();
createContext was introduced to the context api in React v16.x, see here. As per your package.json, you are using React v15.5.4, hence the error.
You have 2 options: (1) upgrade react to v16.x or (2) downgrade styled-components to v3.x - this will do it because styled-components v3.x uses the old react context api.
Also, you can read here about why your code breaks when using multiple versions of react at the same time.
Related
I've been trying to deploy this simple app to Heroku and my app works fine when running locally on AWS but when I try to deploy it I get error message:
bundle.js:73 Uncaught Error: Module build failed: Error: Cannot find module '#babel/plugin-proposal-class-properties' from '/app'
at Function.resolveSync [as sync] (/app/node_modules/resolve/lib/sync.js:111:15)
at resolveStandardizedName (/app/node_modules/#babel/core/lib/config/files/plugins.js:101:31)
at resolvePlugin (/app/node_modules/#babel/core/lib/config/files/plugins.js:54:10)
at loadPlugin (/app/node_modules/#babel/core/lib/config/files/plugins.js:62:20)
at createDescriptor (/app/node_modules/#babel/core/lib/config/config-descriptors.js:154:9)
at /app/node_modules/#babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (/app/node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPluginDescriptors (/app/node_modules/#babel/core/lib/config/config-descriptors.js:105:10)
at /app/node_modules/#babel/core/lib/config/config-descriptors.js:63:49
at cachedFunction (/app/node_modules/#babel/core/lib/config/caching.js:33:19)
at plugins (/app/node_modules/#babel/core/lib/config/config-descriptors.js:28:77)
at mergeChainOpts (/app/node_modules/#babel/core/lib/config/config-chain.js:314:26)
at /app/node_modules/#babel/core/lib/config/config-chain.js:278:7
at buildRootChain (/app/node_modules/#babel/core/lib/config/config-chain.js:68:29)
at loadPrivatePartialConfig (/app/node_modules/#babel/core/lib/config/partial.js:57:55)
at loadPartialConfig (/app/node_modules/#babel/core/lib/config/partial.js:82:18)
at Object.<anonymous> (/app/node_modules/babel-loader/lib/index.js:155:26)
at Generator.next (<anonymous>)
at asyncGeneratorStep (/app/node_modules/babel-loader/lib/index.js:3:103)
at _next (/app/node_modules/babel-loader/lib/index.js:5:194)
at /app/node_modules/babel-loader/lib/index.js:5:364
at Object.<anonymous> (bundle.js:73:7)
at __webpack_require__ (bundle.js:20:30)
at bundle.js:66:18
at bundle.js:69:10
My package.json file looks like this:
{
"name": "Plant-species-app",
"version": "1.0.0",
"description": "Creating a simple CRUD app with NodeJS, MongoDB, GraphQL, React and Apollo",
"main": "index.js",
"scripts": {
"heroku-postbuild": "npm install --production",
"dev": "nodemon index.js --ignore client",
"start": "npm run dev"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-cache-inmemory": "^1.5.1",
"apollo-client": "^2.5.1",
"apollo-link-http": "^1.5.14",
"axios": "^0.15.3",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"body-parser": "^1.16.0",
"connect-mongo": "^1.3.2",
"css-loader": "^0.26.1",
"dotenv": "^16.0.3",
"express": "^4.16.4",
"express-graphql": "^0.8.0",
"express-session": "^1.15.0",
"graphql": "^14.3.0",
"graphql-tag": "^2.10.1",
"html-entities": "^2.3.3",
"html-webpack-plugin": "^2.26.0",
"lodash": "^4.17.4",
"mongoose": "^5.5.7",
"nodemon": "*",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"python": "^0.0.4",
"react": "^16.8.6",
"react-apollo": "^2.5.5",
"react-dom": "^16.8.6",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"style-loader": "^0.13.1",
"webpack": "^2.2.0",
"webpack-dev-middleware": "^1.9.0"
},
"engines": {
"node": "16.17.0",
"npm": "8.15.0"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-proposal-class-properties": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/preset-react": "^7.0.0"
}
}
.babelrc contains:
{
"presets": ["#babel/preset-env", "#babel/preset-react"],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
Here is my webpack.config.js:
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './client/index.js',
output: {
path: '/',
filename: 'bundle.js'
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
use: ['style-loader', 'css-loader'],
test: /\.css$/
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'client/index.html'
})
]
};
I'm struggling to figure out where the issue is, I'm assuming it's either in my .bablerc file or webpack.config.js but I also read about the potential difficulty with .babelrc loading here. I'm very new to programming so please excuse my ignorance.
I've tried moving all the babel devdependencies to dependencies in package.json with no change.
I've also tried removing the contents of the .bablerc file with no luck. If I comment out the plugins in the .babelrc file, the same error appears although #babel/plugin-proposal-class-properties is replaced by #babel/preset-env
Can anyone point me in the right direction or explain how to diagnose this issue?
Help would be greatly appreciated
On a ReactJS project, it is using webpack for building it. Everytime I run the script for production build, it is giving me a development build (getting This page is using the development build of React. from React Developer Tools). I need to get the production build.
The webpack has been configured by some other developer who's not around and I don't have any prior experience with webpack. So I am facing a really hard time to resolve the error.
package.json:
{
"name": "enquiry-form-rnd-2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "cross-env BUILD_ENV=dev webpack-dev-server --config ./webpack.config.js --mode development --progress --colors --port 3002",
"build:stage": "BUILD_ENV=STAGE webpack --mode production",
"build:prod": "BUILD_ENV=prod webpack --mode production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.4.4",
"#babel/plugin-proposal-class-properties": "^7.4.4",
"#babel/preset-env": "^7.4.4",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"babel-plugin-transform-regenerator": "^6.26.0",
"concurrently": "^4.1.0",
"css-loader": "^2.1.1",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^5.0.0",
"gulp-clean": "^0.4.0",
"gulp-install": "^1.1.0",
"gulp-open": "^3.0.1",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"node-sass": "^4.12.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack": "^4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.3.1"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"cross-env": "^5.2.0",
"google-maps-react": "^2.0.2",
"immutable": "^4.0.0-rc.12",
"moment": "^2.24.0",
"numeral": "^2.0.6",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.8",
"react-datetime": "^2.16.3",
"react-dom": "^16.8.6",
"react-intl": "^2.8.0",
"react-notifications-component": "^1.1.1",
"react-redux": "^7.0.3",
"react-responsive": "^6.1.2",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-saga": "^1.0.2",
"reselect": "^4.0.0",
"styled-components": "^4.2.0",
"styled-icons": "^7.14.0",
"validator": "^11.1.0",
"whatwg-fetch": "^3.0.0"
}
}
webpack.config.js:
const webpack = require("webpack");
module.exports = {
entry: ["babel-polyfill", "./src/index.js"],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"]
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.(pdf|jpg|png|gif|svg|ico)$/,
use: [
{
loader: "url-loader"
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: "file-loader"
}
]
},
resolve: {
extensions: ["*", ".js", ".jsx", "css"]
},
output: {
path: __dirname + "/build",
publicPath: "/",
filename: "bundle.js"
},
devServer: {
contentBase: "./dist",
host: "172.16.228.94",
// host: "192.168.2.108",
port: 3002
},
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env.DEBUG": JSON.stringify(process.env.BUILD_ENV),
"process.env.BUILD_ENV": JSON.stringify(process.env.BUILD_ENV)
})
]
};
I'm stuck with adding styled-components library into my reactjs project. I'm getting an error when trying to run my app in browser, not at the building stage. It's quite common:
Here is my webpack config:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
context: path.join(__dirname, 'src'),
entry: {
server: '../server/index.js',
app: './app.jsx',
},
resolve: {
extensions: ['.jsx', '.js'],
},
module: {
rules: [
{
test: /\.(jsx|js)?$/,
use: {
loader: 'babel-loader',
},
},
],
},
target: 'node',
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
filename: './index.html',
excludeChunks: ['server'],
}),
],
};
Here is my babelrc:
{
"presets": ["#babel/preset-env", "#babel/preset-react"],
"plugins": [
"#babel/plugin-transform-runtime",
"babel-plugin-styled-components"
]
}
Here is my styled component:
import React from 'react';
import styled from 'styled-components';
export function SearchPage() {
const Container = styled.div`
text-align: center;
`;
return <Container>test</Container>;
}
Here is my package.json:
{
"devDependencies": {
"#babel/core": "^7.3.4",
"#babel/plugin-transform-runtime": "^7.4.0",
"#babel/preset-env": "^7.3.4",
"#babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"babel-plugin-styled-components": "^1.10.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.11.2",
"eslint": "^5.15.3",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.6.0",
"husky": "^1.3.1",
"jest": "^24.5.0",
"live-server": "^1.2.1",
"nodemon": "^1.18.10",
"npm-run-all": "^4.1.5",
"prettier": "^1.16.4",
"react-redux": "^6.0.1",
"react-router": "^4.4.0",
"redux": "^4.0.1",
"rimraf": "^2.6.3",
"stream": "^0.0.2",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
},
"version": "1.0.0",
"main": "dist/server.js",
"scripts": {
"clean": "rimraf dist build",
"dev": "npm-run-all -p dev:watch server:run dev:server",
"dev:build": "webpack --config webpack.dev.js",
"dev:watch": "yarn run dev:build --watch",
"dev:server": "live-server dist",
"server:run": "nodemon",
"prod:build": "npm-run-all clean webpack --config webpack.prod.js",
"test": "jest"
},
"dependencies": {
"express": "^4.16.4",
"html-webpack-plugin": "^3.2.0",
"webpack-merge": "^4.2.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"styled-components": "^4.2.0"
}
}
I thought that Webpack should bundle all the dependencies. And I don't understand why stream import is not covered by webpack bundling.
I guess that the answer is pretty simple, but I cannot find it. So any advice will be helpful.
The thing is in target: 'node' into my package.json. It's supposed to use only for server-side build not for client.
JavaScript head out of memory while I compile using webpack build system. I don't know what is the problem.
Snapshot of error while on npm run build:prod
I'm using:
OS: Ubuntu 16.04,
RAM: 8Gig,
Processor: Inter Core-i5
Node.js, babel-minify-webpack-plugin.
Reactjs 16.2,and Redux
Here is Webpack.config.js file:
var webpack = require('webpack');
var path = require('path');
const env = process.env.NODE_ENV || 'development'
const MinifyPlugin = require("babel-minify-webpack-plugin");
module.exports = {
entry: {
'/js/app': './frontend/app.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public')
},
module: {
rules: [
{
test: /\.(scss|css|sass)$/i,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
options: {
includePaths: [
path.resolve("./node_modules/")
]
}
}]
},
{
test: /\.js$/,
loader: 'babel-loader',
include: path.join(__dirname, "frontend"),
exclude: path.resolve(__dirname, "node_modules"),
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
loader: 'url-loader?limit=4096&name=[name]-[hash].[ext]'
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
externals: {
jquery: 'jQuery'
},
node: {
fs: "empty",
net: "empty"
},
plugins: [
new webpack.ProvidePlugin({
'videojs': 'video.js',
'window.videojs': 'video.js'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new MinifyPlugin(true, true)
]
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Here is my package.json file:
{
"name": "node-ejs",
"version": "1.0.0",
"description": "this is our first app using nodejs on express server with babel",
"main": "server.js",
"proxy": "http://10.1.0.7",
"scripts": {
"start": "nodemon ./server.js --exec babel-node --presets env",
"build:debug": "webpack -d --progress --colors",
"build:prod": "webpack -p --progress --colors",
"build": "webpack --config webpack.config.js"
},
"keywords": [
"nodejs",
"babel",
"express"
],
"watch": true,
"author": "",
"license": "ISC",
"dependencies": {
"#blueprintjs/core": "^1.35.0",
"axios": "^0.17.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-minify-builtins": "^0.4.0",
"babel-plugin-minify-flip-comparisons": "^0.4.0",
"babel-preset-es2015": "^6.24.1",
"body-parser": "^1.18.2",
"bootstrap": "^3.3.7",
"ejs": "^2.5.7",
"express": "^4.16.2",
"express-ejs-extend": "0.0.1",
"firebase": "^4.8.2",
"js-file-download": "^0.4.1",
"json-loader": "^0.5.7",
"material-design-icons": "^3.0.1",
"moment": "^2.22.0",
"node-sass": "^4.7.2",
"nodemon": "^1.14.5",
"npm": "^5.8.0",
"npm-install-peers": "^1.2.1",
"pure-render-decorator": "^1.2.1",
"query-string": "^6.0.0",
"re-base": "^3.2.2",
"react-addons-css-transition-group": "^15.6.2",
"react-bootstrap": "^0.31.5",
"react-breadcrumbs-dynamic": "^1.0.12",
"react-dom": "^16.2.0",
"react-file-download": "^0.3.5",
"react-jplayer": "^7.1.2",
"react-notifications": "^1.4.3",
"react-owl-carousel2": "^0.2.1",
"react-pager": "^1.3.3",
"react-placeholder": "^2.0.0",
"react-redux": "^5.0.6",
"react-rev-slider": "^1.0.1",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-router-redux": "^4.0.8",
"react-share": "^1.19.0",
"react-slick": "^0.20.0",
"redux": "^3.7.2",
"redux-promise-middleware": "^5.0.0",
"redux-thunk": "^2.2.0",
"sass-loader": "^6.0.6",
"save-dev": "^2.0.0",
"scss-loader": "0.0.1",
"slick-carousel": "^1.8.1",
"update": "^0.7.4",
"video.js": "^6.6.0",
"videojs-contrib-dash": "^2.9.2",
"videojs-ima": "^1.0.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},
"devDependencies": {
"#babel/preset-env": "^7.0.0-beta.44",
"babel-cli": "^6.26.0",
"babel-minify": "^0.4.0",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.4.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"babel-register": "^6.26.0",
"css-loader": "^0.28.7",
"file-loader": "^1.1.6",
"img-loader": "^2.0.0",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"postcss-loader": "^2.0.10",
"react": "^16.2.0",
"react-dfp": "^0.7.0",
"react-modal": "^3.1.10",
"react-router-bootstrap": "^0.24.4",
"style-loader": "^0.19.1",
"url-loader": "^0.6.2"
}
}
I can pass this error by this code
$ NODE_OPTIONS="--max-old-space-size=1024" yarn test
I have style-loader, css-loader, sass-loader and node-sass installed. And i think the webpack.config file is set up properly...although it seems I'm missing something. please help!
package.json
{
"name": "pluralsight-redux-starter",
"version": "1.0.0",
"description": "Starter kit for React and Redux Pluralsight course by Cory House",
"author": "Cory House",
"license": "MIT",
"//": "alternative for this include gulp and grunt",
"scripts": {
"//": "react specific library, you can use redux with other libraries as well, like angular etc...",
"prestart": "babel-node tools/startMessage.js",
"start": "npm-run-all --parallel open:src lint:watch test:watch",
"open:src": "babel-node tools/srcServer.js",
"lint": "node_modules/.bin/esw webpack.config.* src tools",
"lint:watch": "npm run lint -- --watch",
"test": "mocha --reporter spec tools/testSetup.js \"src/**/*.test.js\"",
"test:watch": "npm run test -- --watch",
"clean-dist": "npm run remove-dist && mkdir dist",
"prebuild": "npm-run-all clean-dist test link build:html",
"build": "babel-node tools/build.js",
"postbuild": "babel-node tools/distServer.js"
},
"dependencies": {
"babel-polyfill": "6.8.0",
"bootstrap": "3.3.6",
"css-loader": "^0.23.1",
"jquery": "2.2.3",
"node-sass": "^3.8.0",
"react": "15.1.0",
"react-dom": "15.0.2",
"react-redux": "4.4.5",
"react-router": "2.4.0",
"react-router-redux": "4.0.4",
"react-toolbox": "^1.0.1",
"redux": "3.5.2",
"redux-thunk": "2.0.1",
"sass-loader": "^0.5.0",
"style-loader": "^0.13.1",
"toastr": "2.1.2"
},
"devDependencies": {
"babel-cli": "6.8.0",
"babel-core": "6.8.0",
"babel-loader": "6.2.4",
"babel-plugin-react-display-name": "2.0.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"babel-preset-react-hmre": "1.1.1",
"babel-register": "6.8.0",
"colors": "1.1.2",
"compression": "1.6.1",
"cross-env": "1.0.7",
"css-loader": "0.23.1",
"enzyme": "2.2.0",
"eslint": "2.9.0",
"eslint-plugin-import": "1.6.1",
"eslint-plugin-react": "5.0.1",
"eslint-watch": "2.1.11",
"eventsource-polyfill": "0.9.6",
"expect": "1.19.0",
"express": "4.13.4",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.8.5",
"jsdom": "8.5.0",
"mocha": "2.4.5",
"nock": "8.0.0",
"npm-run-all": "1.8.0",
"normalize.css": "^4.0.0",
"react-addons-css-transition-group": "^15.0.0",
"open": "0.0.5",
"postcss-loader": "0.8.2",
"react": "^15.0.2",
"react-addons-test-utils": "15.0.2",
"redux-immutable-state-invariant": "1.2.3",
"redux-mock-store": "1.0.2",
"rimraf": "2.5.2",
"sass-loader": "0.5",
"style-loader": "0.13.1",
"url-loader": "0.5.7",
"webpack": "1.13.0",
"webpack-dev-middleware": "1.6.1",
"webpack-hot-middleware": "2.10.0"
},
"repository": {
"type": "git",
"url": "https://github.com/coryhouse/pluralsight-redux-starter"
}
}
webpack.config.dev.js
import webpack from 'webpack';
import path from 'path';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
export default {
debug: true,
devtool: 'cheap-module-eval-source-map',
noInfo: false,
entry: [
'eventsource-polyfill', // necessary for hot reloading with IE
'webpack-hot-middleware/client?reload=true', //note that it reloads the page if hot module reloading fails.
'./src/index.js'
],
target: 'web',
output: {
path: __dirname + '/dist', // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './src'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.css', '.scss', '.js']
},
// Tells webpack the types of files that we want it to handle.
module: {
loaders: [
{test: /\.js$/, include: path.join(__dirname, 'src'), loaders: ['babel']},
{test: /\.s?css$/, loaders: ['style', 'css', 'sass']},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
{test: /\.(woff|woff2)$/, loader: 'url?prefix=font/&limit=5000'},
{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'}
]
}
};
error message in console:
SyntaxError: /Users/Macbook/projects/pluralsight-redux-starter/src/styles/test.scss: Unexpected token (1:5)
> 1 | form {
| ^
2 | h1 {
3 | color: red;
4 | }
at Parser.pp.raise (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/location.js:22:13)
at Parser.pp.unexpected (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/util.js:89:8)
at Parser.pp.semicolon (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/util.js:76:38)
at Parser.pp.parseExpressionStatement (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/statement.js:499:8)
at Parser.parseExpressionStatement (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/plugins/flow.js:52:20)
at Parser.pp.parseStatement (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/statement.js:168:17)
at Parser.parseStatement (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/plugins/flow.js:30:22)
at Parser.pp.parseBlockBody (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/statement.js:529:21)
at Parser.pp.parseTopLevel (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/statement.js:36:8)
at Parser.parse (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/parser/index.js:129:19)
at parse (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babylon/lib/index.js:47:47)
at File.parse (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-core/lib/transformation/file/index.js:540:58)
at File.parseCode (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-core/lib/transformation/file/index.js:626:20)
at /Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-core/lib/transformation/pipeline.js:52:12
at File.wrap (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-core/lib/transformation/file/index.js:586:16)
at Pipeline.transform (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-core/lib/transformation/pipeline.js:50:17)
at Object.transformFileSync (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-core/lib/api/node.js:152:10)
at compile (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:129:20)
at loader (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:158:14)
at Object.require.extensions.(anonymous function) [as .js] (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (CourseForm.js:4:1)
at Module._compile (module.js:541:32)
at loader (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (CourseForm.Enzyme.test.js:12:1)
at Module._compile (module.js:541:32)
at loader (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at /Users/Macbook/projects/pluralsight-redux-starter/node_modules/mocha/lib/mocha.js:219:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/mocha/lib/mocha.js:216:14)
at Mocha.run (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/mocha/lib/mocha.js:468:10)
at loadAndRun (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/mocha/bin/_mocha:359:22)
at Object.<anonymous> (/Users/Macbook/projects/pluralsight-redux-starter/node_modules/mocha/bin/_mocha:376:3)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:449:3
test.scss
form {
h1 {
color: red;
}
}
webpack-validator output:
import webpack from webpack;
seems to be causing a problem for webpack-validator, not sure why this is. I'm not convinced it is related to my scss loading issue.
==> webpack-validator webpack.config.dev.js
Reading: webpack.config.dev.js
/Users/Macbook/projects/pluralsight-redux-starter/webpack.config.dev.js:1
(function (exports, require, module, __filename, __dirname) { import webpack from 'webpack';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at validateConfig (/usr/local/lib/node_modules/webpack-validator/dist/bin/validate-config.js:13:16)
at /usr/local/lib/node_modules/webpack-validator/dist/bin/webpack-validator.js:35:32
From the error it looks like you are just missing a brace somewhere in your .scss
SyntaxError: /Users/Macbook/projects/pluralsight-redux-starter/src/styles/test.scss: Unexpected token (1:5)
> 1 | form {
| ^
2 | h1 {
3 | color: red;
4 | }
Double check test.scss and make sure everything is fine.
Resolved the problem using the following package:
https://www.npmjs.com/package/ignore-styles
added:
mocha--require ignore-styles
to test script and problem solved.
Thanks #eblin
Can you try and extend your config to include the following:
export default {
resolve: {
extensions: ['', '.css', '.scss', '.js']
},
...
}
Problem solved.
Updated sass-loader from 0.5.0 to 3.2.0, and tweaked the webpack.config file. See below, the updated package.json and webpack.config. Allows me to use bootstrap and react-toolbox styles.
package.json
{
"name": "pluralsight-redux-starter",
"version": "1.0.0",
"description": "Starter kit for React and Redux Pluralsight course by Cory House",
"author": "Cory House",
"license": "MIT",
"//": "alternative for this include gulp and grunt",
"scripts": {
"//": "react specific library, you can use redux with other libraries as well, like angular etc...",
"prestart": "babel-node tools/startMessage.js",
"start": "npm-run-all --parallel open:src lint:watch test:watch",
"open:src": "babel-node tools/srcServer.js",
"lint": "node_modules/.bin/esw webpack.config.* src tools",
"lint:watch": "npm run lint -- --watch",
"test": "mocha --require ignore-styles --reporter spec tools/testSetup.js \"src/**/*.test.js\"",
"test:watch": "npm run test -- --watch",
"clean-dist": "npm run remove-dist && mkdir dist",
"prebuild": "npm-run-all clean-dist test link build:html",
"build": "babel-node tools/build.js",
"postbuild": "babel-node tools/distServer.js"
},
"dependencies": {
"babel-polyfill": "6.8.0",
"bootstrap": "3.3.6",
"css-loader": "^0.23.1",
"jquery": "2.2.3",
"minimatch": "^3.0.2",
"node-sass": "^3.8.0",
"react": "15.1.0",
"react-dom": "15.0.2",
"react-redux": "4.4.5",
"react-router": "2.4.0",
"react-router-redux": "4.0.4",
"react-toolbox": "^1.0.1",
"redux": "3.5.2",
"redux-thunk": "2.0.1",
"resolve-path-webpack-plugin": "^1.1.0",
"sass-loader": "^3.2.1",
"style-loader": "^0.13.1",
"toastr": "2.1.2",
"webpack-validator": "^2.2.0"
},
"devDependencies": {
"babel-cli": "6.8.0",
"babel-core": "6.8.0",
"babel-loader": "6.2.4",
"babel-plugin-react-display-name": "2.0.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"babel-preset-react-hmre": "1.1.1",
"babel-register": "6.8.0",
"colors": "1.1.2",
"compression": "1.6.1",
"cross-env": "1.0.7",
"css-loader": "0.23.1",
"enzyme": "2.2.0",
"eslint": "2.9.0",
"eslint-plugin-import": "1.6.1",
"eslint-plugin-react": "5.0.1",
"eslint-watch": "2.1.11",
"eventsource-polyfill": "0.9.6",
"expect": "1.19.0",
"express": "4.13.4",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.8.5",
"ignore-styles": "^4.0.0",
"jsdom": "8.5.0",
"mocha": "2.4.5",
"nock": "8.0.0",
"normalize.css": "^4.0.0",
"npm-run-all": "1.8.0",
"open": "0.0.5",
"postcss-loader": "0.8.2",
"react": "^15.0.2",
"react-addons-css-transition-group": "^15.0.0",
"react-addons-test-utils": "15.0.2",
"redux-immutable-state-invariant": "1.2.3",
"redux-mock-store": "1.0.2",
"rimraf": "2.5.2",
"sass-loader": "^3.2.0",
"style-loader": "0.13.1",
"toolbox-loader": "0.0.3",
"url-loader": "0.5.7",
"webpack": "1.13.0",
"webpack-dev-middleware": "1.6.1",
"webpack-hot-middleware": "2.10.0"
},
"repository": {
"type": "git",
"url": "https://github.com/coryhouse/pluralsight-redux-starter"
}
}
webpack.config.dev.js
import webpack from 'webpack';
import path from 'path';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const modulesPath = path.join(__dirname, 'node_modules');
const autoprefixer = require('autoprefixer');
export default {
debug: true,
devtool: 'source-map',
noInfo: false,
entry: [
'eventsource-polyfill', // necessary for hot reloading with IE
'webpack-hot-middleware/client?reload=true', //note that it reloads the page if hot module reloading fails.
'./src/index.js'
],
target: 'web',
output: {
path: __dirname + '/dist', // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './src'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.css', '.scss', '.js', '.json'],
modulesDirectories: ['node_modules']
},
postcss: [autoprefixer],
toolbox: {
theme: path.join(__dirname, 'src/styles/variables.scss')
},
// Tells webpack the types of files that we want it to handle.
module: {
loaders: [
{test: /(\.js|\.jsx)$/,
include: path.join(__dirname, 'src'),
loaders: ['babel']
},
{
test: /\.s?css$/,
loaders: ['style', 'css', 'sass'],
exclude: /(node_modules)\/react-toolbox/
},
{
test : /(\.scss|\.css)$/,
include : /(node_modules)\/react-toolbox/,
loaders : [
require.resolve('style-loader'),
require.resolve('css-loader') + '?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
require.resolve('sass-loader') + '?sourceMap', 'toolbox'
]
},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
{test: /\.(woff|woff2)$/, loader: 'url?prefix=font/&limit=5000'},
{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'}
]
}
};