I'm having an issue where babel-loader doesn't appear to be able to handle any JSX code. While I'm familiar with how the higher end code of the site works, I didn't set up the environment, which is how I got in this situation!
I'm trying to reverse engineer the babel, webpack, neutrino config so I can use it elsewhere, and so I can do some package updates.
Error in terminal after running npm run develop
ℹ 「wds」: Project is running at http://localhost:5000/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /Users/xxx/Documents/GitHub/React-Boilerplate
ℹ 「wds」: 404s will fallback to /index.html
✖ 「wdm」: Time: 6205ms
ERROR in ./src/index.js 7:16
Module parse failed: Unexpected token (7:16)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import './globals/css/variables.css';
| import './globals/css/global.css';
> ReactDOM.render(<div>text in here</div>, document.getElementById('root'));
ℹ 「wdm」: Failed to compile.
So the code is hanging as soon as the babel-loader sees JSX code.
package.json
{
"name": "xxx",
"version": "0.0.0",
"description": "xxx",
"scripts": {
"develop": "webpack-dev-server --mode development",
"build": "webpack --mode production",
"generate": "plop --plopfile ./generators/plopfile.js",
"clean": "rm -rf ./dist"
},
"author": "xxx",
"license": "xxx",
"private": true,
"dependencies": {
"#fortawesome/free-solid-svg-icons": "^5.12.1",
"#material-ui/core": "^4.9.13",
"#material-ui/icons": "^4.11.2",
"#tomorrow/bloom": "^0.1.2",
"draft-js": "^0.11.4",
"draftjs-to-html": "^0.9.1",
"eslint": "^5.16.0",
"html-to-draftjs": "^1.5.0",
"json-query": "^2.2.2",
"mobx": "^5.9.0",
"mobx-react": "^5.4.3",
"postcss": "^8.2.4",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"react-draft-wysiwyg": "^1.14.4",
"react-hot-loader": "^4.8.0",
"react-promise-tracker": "^2.0.5",
"react-router-dom": "^4.3.1",
"react-select": "^2.4.2",
"react-spinners": "^0.8.3",
"shortid": "^2.2.15"
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#babel/plugin-proposal-class-properties": "^7.4.0",
"#babel/plugin-proposal-decorators": "^7.4.0",
"#babel/preset-env": "^7.12.11",
"#neutrinojs/react": "^9.0.0-rc.0",
"babel-core": "^6.0.20",
"babel-loader": "^8.2.2",
"babel-merge": "^2.0.1",
"babel-plugin-react-css-modules": "^5.2.3",
"babel-polyfill": "^6.0.16",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.0.15",
"dotenv": "^7.0.0",
"neutrino": "^9.0.0-rc.0",
"plop": "^2.3.0",
"postcss-aspect-ratio": "^1.0.2",
"postcss-custom-media": "^7.0.7",
"postcss-flexbugs-fixes": "^4.1.0",
"postcss-lh": "^2.0.2",
"postcss-loader": "^3.0.0",
"postcss-nesting": "^7.0.0",
"postcss-preset-env": "^6.6.0",
"postcss-responsive-type": "^1.0.0",
"postcss-subgrid": "^0.2.1",
"prettier": "^1.16.4",
"stylelint": "^9.10.1",
"stylelint-config-recommended": "^2.1.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.1"
}
}
webpack.config.js
const neutrino = require('neutrino');
module.exports = neutrino().webpack();
.neutrinorc.js
const { resolve } = require('path');
const babelMerge = require('babel-merge');
// require('dotenv').config();
const react = require('#neutrinojs/react');
module.exports = neutrino => {
const { config } = neutrino;
// Configure react preset
neutrino.use(react, {
html: {
title: 'Boilerplate'
},
hot: true,
devServer: {
https: true,
port: 3000
},
style: {
loaders: ['postcss-loader']
}
});
// Customize Babel
config.module
.rule('compile')
.use('babel')
.tap(options =>
babelMerge(
{
plugins: [
['#babel/plugin-proposal-decorators', { legacy: true }],
['#babel/plugin-proposal-class-properties', { loose: true }],
[
'babel-plugin-react-css-modules',
{
generateScopedName: '[path]--[local]', //--[hash:base64:5]' // took this out as code wasn't working locally on PC,
webpackHotModuleReloading: false, //can be true in dev if
autoResolveMultipleImports: true
}
]
]
},
options
)
);
// Customize CSS modules
config.module
.rule('style-modules')
.use('css-modules')
.tap(options =>
Object.assign(
options,
(options.localIdentName = '[path]--[local]') //--[hash:base64:5]'// took this out as code wasn't working locally on PC,
)
);
// Set webpack options
config.output.path(resolve('./public'));
};
I suspect I need to add a new plugin to the babelMerge function - any help is wildly appreciated!
Oh, and here's src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
// import App from './containers/App';
import '#tomorrow/bloom/bloom.css';
import './globals/css/variables.css';
import './globals/css/global.css';
ReactDOM.render(<div>text in here</div>, document.getElementById('root'));
#neutrinojs/style-loader is Neutrino middleware for loading and importing stylesheets from modules.
I did not find style-loader middleware installed in your dev dependency list. You can try it.
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
I have created an alias for react and react-dom in my next.config.js. This is my next.config.js:
var path = require("path");
module.exports = (phase) => {
return {
// typescript: {
// ignoreBuildErrors: false,
// },
webpack5: true,
webpack(config, options) {
// const { isServer } = options;
// if (!isServer) {
// config.resolve.fallback.fs = false;
// }
config.module.rules.push({
test: /\.svg$/,
loader: "#svgr/webpack",
});
config.resolve.alias["react"] = path.resolve(
__dirname,
"shared-js/node_modules/react"
);
config.resolve.alias["react-dom"] = path.resolve(
__dirname,
"shared-js/node_modules/react-dom"
);
console.log(path.resolve(__dirname, "shared-js/node_modules/react-dom"));
return config;
},
};
};
Why am I doing this?
I have a component library, which is based on material ui. This is imported to my nextjs app via a submodule (shared-js). This is the package.json for my component library:
{
"name": "my-component-library",
"version": "1.0.0",
"description": "",
"author": "",
"private": true,
"main": "dist/index.js",
"module": "dist/index.modern.js",
"umd": "dist/index.min.js",
"source": "src/index.js",
"scripts": {
"start": "rollup -c -w",
"build": "NODE_ENV=production rollup -c",
"build-dev": "NODE_ENV=develop rollup -c --minifyInternalExports=false",
"prettier": "prettier --write ./src"
},
"peerDependencies": {
"eslint": "^8.15.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"license": "ISC",
"dependencies": {
"#emotion/react": "^11.7.1",
"#emotion/styled": "^11.6.0",
"#mui/icons-material": "^5.4.2",
"#mui/material": "^5.4.1",
"#mui/styles": "^5.4.2",
"#mui/x-data-grid": "^5.7.0",
"#rollup/plugin-node-resolve": "^13.3.0",
"prop-types": "^15.8.1",
"react-beautiful-dnd": "^13.1.0",
"react-grid-layout": "^1.3.4",
"react-resizable": "^3.0.4",
"recharts": "^2.1.9",
"rollup-plugin-import-css": "^3.0.3",
"styled-components": "^5.3.3",
"use-react-screenshot": "^3.0.0"
},
"devDependencies": {
"#babel/cli": "^7.17.10",
"#babel/core": "^7.17.10",
"#babel/plugin-transform-runtime": "^7.17.10",
"#babel/preset-env": "^7.17.10",
"#babel/preset-react": "^7.16.7",
"#rollup/plugin-babel": "^5.3.1",
"#rollup/plugin-commonjs": "^21.0.2",
"#svgr/rollup": "^6.2.1",
"babel-eslint": "^10.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-standard": "^5.0.0",
"prettier": "^2.6.2",
"rollup": "^2.72.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-filesize": "^9.1.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.6.0"
},
"files": [
"dist"
]
}
Here is my package.json for my nextjs app:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"name": "frontend",
"version": "1.0.0",
"main": "index.js",
"repository": "",
"author": "",
"license": "MIT",
"dependencies": {
"next": "^12.1.5",
"react": "^18.1.0",
"react-dom": "^18.1.0"
}
}
And my folder structure for the project:
-.next
-node_modules
-pages
-shared-js
--node_modules
--package.json
package.json
next.config.js
The problem is, that I have two conflicting versions of react and react-dom (I guess) in my shared-js/node_modules and the other ones in the node_modules folder of my nextjs app. This caused the error "Invalid hook call" whenever I tried to import a component to my nextjs app. I looked into the documentation and saw that this might be because of two conflicting react / react-dom versions, which is indeed the case. So I tried to avoid this by defining this alias in my next.config.js.
Which led me here. Whenever I run npm run dev or npm run build for my nextjs app, I get this error, telling me that react-dom is apparently missing:
wait - compiling /_error (client and server)...
wait - compiling...
error - ./node_modules/next/dist/client/index.js:513:35
Module not found: Can't resolve 'react-dom/client'
Why is that? The path is correct, the dependency is there but still I get this error. Is there anything I am missing? Or something I am doing wrong?
What I already tried: Deleting node_mdoules and package-lock.json from both nextjs and my component library and reinstall them. Deleting .next and restart via npm run dev
that's how I solved the problem with the conflicting versions.
Good description of the problem: https://blog.maximeheckel.com/posts/duplicate-dependencies-npm-link/
My next.config.js
var path = require("path");
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.resolve.alias["react"] = path.resolve("./node_modules/react");
return config;
},
};
I got this error while setup my react app using the webpack and babel. I try to change the version of babel but still getting the same error. I'm not getting where's the problem.
ERROR in ./src/index.jsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/arslan/Downloads/code/node_modules/babel-preset-es2015/lib/index.js
at createDescriptor (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-descriptors.js:178:11)
at items.map (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-descriptors.js:101:10)
at presets (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-chain.js:320:26)
at /home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/home/arslan/Downloads/code/node_modules/#babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig
Here's my Index.jsx File which is the root file.
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'
import store from './store'
import Routes from './routes'
import './assets/scss/style.css';
import { authCheck } from './modules/auth/store/actions'
store.dispatch(authCheck())
ReactDOM.render(
<Provider store={store}>
<Routes />
</Provider>
,document.getElementById('app'));
Here's my Package.json File which includes all the dependencies.
{
"name": "bebes",
"version": "1.0.0",
"description": "",
"main": "index.jsx",
"scripts": {
"start": "webpack-dev-server --open --mode development",
"build": "webpack --mode production"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.0",
"path": "^0.12.7",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"require": "^2.4.20",
"webpack-encoding-plugin": "^0.3.1"
},
"devDependencies": {
"#babel/core": "^7.6.4",
"#babel/plugin-proposal-class-properties": "^7.2.3",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.6.3",
"#babel/preset-es2015": "^7.0.0-beta.53",
"#babel/preset-react": "^7.0.0",
"#material-ui/core": "^3.9.3",
"#material-ui/icons": "^3.0.2",
"axios": "^0.18.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-preset-es2015": "^6.24.1",
"bootstrap": "4.1.3",
"chart.js": "2.7.2",
"chroma-js": "^1.4.1",
"firebase": "^5.7.2",
"history": "4.7.2",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"immutability-helper": "2.7.1",
"joi": "^13.7.0",
"joi-validation-strategy": "^0.3.3",
"lodash": "^4.17.11",
"moment": "^2.23.0",
"namor": "^1.1.1",
"node-sass": "^4.10.0",
"node-sass-chokidar": "^1.3.4",
"npm-run-all": "4.1.3",
"prop-types": "^15.6.2",
"react": "^16.7.0",
"react-big-calendar": "0.19.2",
"react-bootstrap-sweetalert": "^4.4.1",
"react-bootstrap-switch": "^15.5.3",
"react-bootstrap-table": "^4.3.1",
"react-bootstrap-wizard": "0.0.5",
"react-c3-component": "^1.4.0",
"react-c3js": "^0.1.20",
"react-chartjs-2": "^2.7.4",
"react-datetime": "^2.16.3",
"react-dom": "^16.7.0",
"react-iframe": "1.3.0",
"react-jvectormap": "0.0.3",
"react-loadable": "^5.5.0",
"react-perfect-scrollbar": "1.2.0",
"react-redux": "^6.0.1",
"react-router-dom": "4.2.2",
"react-scripts": "2.1.3",
"react-select": "^2.2.0",
"react-sparklines": "^1.7.0",
"react-stepzilla": "^4.8.0",
"react-table": "^6.8.6",
"react-tagsinput": "^3.19.0",
"react-validation": "^3.0.7",
"react-validation-mixin": "^5.4.0",
"reactstrap": "6.4.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"ree-validate": "^3.0.2",
"sweetalert": "^2.1.2",
"validator": "^10.10.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.4.1"
}
}
The configuration that i use for the webpack is given below
const HtmlWebPackPlugin = require("html-webpack-plugin");
const EncodingPlugin = require('webpack-encoding-plugin');
const path = require('path');
const webpack = require('webpack');
const { join, resolve } = require('path');
module.exports = {
mode: 'development',
entry: './src/index.jsx',
output: {
path:path.resolve(__dirname, 'dist'),
filename:'bundle.js'
},
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
compress: true,
historyApiFallback: true,
watchOptions: { aggregateTimeout: 300, poll: 1000 },
inline: true,
host: process.env.HOST, // set in Dockerfile for client container
port: process.env.PORT, // set in Dockerfile for client container
disableHostCheck: true, // when manipulating /etc/hosts
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/javascript; charset=windows-1251'
}
},
module: {
rules: [
{
test: /\.(js|jsx|css)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
babelrc: true,
presets: ['#babel/preset-env']
}
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: './public/index.html',
filename: 'index.html'
})
]
};
The configuration file for the .babelrc is here.
{
"presets": [
"#babel/preset-env", "#babel/preset-react","es2015", "react", "stage-1"
],
"plugins": [
"#babel/plugin-proposal-class-properties",
"#babel/plugin-syntax-dynamic-import"
]
}
The error you are getting is because you are trying to use a Babel 6 preset on Babel 7.
"#babel/preset-env", "#babel/preset-react","es2015", "react", "stage-1"
is not quite right.
"es2015" was replaced by "#babel/preset-env"
"react" was replaced by "#babel/preset-react"
"stage-1" does not exist for Babel 7 and you should use the individual plugins that you actually want to enable.
Change your config to
"presets": [
"#babel/preset-env", "#babel/preset-react"
],
and then add more plugins if there are other things that give you errors when you compile.
I think you should try the following
npm uninstall --save babel-loader
npm uninstall --save #babel/core
npm install --save-dev babel-loader#^7
That worked for me.
Also have a look at your dependencies, you are having some duplicates that could lead you to errors at some moment.
I am new to React and Jest and during my first experiment I got stuck with the following error when running jest --watchAll:
FAIL src/components/App.test.js
● Test suite failed to run
Cannot find module '#babel/preset-register' from '/Users/joaomatos/projects/dummy'
- If you want to resolve "#babel/register", use "module:#babel/register"
at Function.module.exports [as sync] (node_modules/resolve/lib/sync.js:74:15)
at resolveStandardizedName (node_modules/#babel/core/lib/config/files/plugins.js:101:31)
at resolvePreset (node_modules/#babel/core/lib/config/files/plugins.js:58:10)
at loadPreset (node_modules/#babel/core/lib/config/files/plugins.js:77:20)
at createDescriptor (node_modules/#babel/core/lib/config/config-descriptors.js:154:9)
at node_modules/#babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (node_modules/#babel/core/lib/config/config-descriptors.js:101:10)
at presets (node_modules/#babel/core/lib/config/config-descriptors.js:47:19)
I installed several babel packages namely babel register, but I cannot find anything else related to #babel/preset-register. My package.json:
{
"name": "dummy",
"version": "0.1.0",
"private": true,
"dependencies": {
"#babel/preset-env": "^7.7.1",
"acorn": "^7.1.0",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-preset-env": "^1.7.0",
"history": "^4.10.1",
"npm-preset": "^1.5.0",
"parcel": "^1.12.4",
"react": "^16.11.0",
"react-app-polyfill": "^1.0.4",
"react-dev-utils": "^9.1.0",
"react-dom": "^16.6.3",
"react-dropzone": "^10.1.10",
"react-file-drop": "^0.2.8",
"react-flip-move": "^3.0.4",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "3.2.0",
"react-switch": "^5.0.1",
"react-test-renderer": "^16.11.0",
"redux": "^4.0.4",
"typescript": "^3.7.2"
},
"scripts": {
"dev": "parcel src/index.html",
"build": "parcel build src/index.html",
"start": "npm run build && live-server dist",
"test": "jest --watchAll"
},
"devDependencies": {
"#babel/core": "^7.7.2",
"#babel/plugin-proposal-class-properties": "^7.7.0",
"#babel/preset-react": "^7.7.0",
"#babel/preset-stage-2": "^7.0.0",
"#babel/register": "^7.7.0",
"babel-loader": "^8.0.6",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1"
}
}
and .babel.rc:
{
"plugins": [
"#babel/plugin-proposal-class-properties"
],
"env": {
"test": {
"presets": [
"env",
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-stage-2",
"#babel/register",
"stage-2",
"react"
],
"plugins": [
"transform-export-extensions",
"transform-class-properties"
],
"only": [
"./**/*.js",
"node_modules/jest-runtime"
]
}
}
And my test:
import React from 'react';
import Enzyme, {shallow} from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import App from './App';
Enzyme.configure({adapter: new EnzymeAdapter()});
test(
'renders without crashing',
() => {
const wrapper = shallow(<App />);
expect(wrapper).toBeTruthy();
}
);
Does anyone know why I am getting this error?
Thank you for your help.
Babel-register is not a preset, hence the error message you are facing. Are you sure you need it for a starter project? Try removing it from the presets array in babel.rc
I'm so confuse how to setting up my project to deploy my project to my development server. I got a problem after I upload my files to the server.
this is what my browser shows if i open my website url. I read some post in stackoverflow How to deploy a React App on Apache web server and tells that I need to npm run build. Yes I tried it but my terminal says
missing build script
I have question do i need to configure the htaccess? I don't know where to configure in laravel or in react?
Here's my package.json file
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"build": "webpack --mode production"
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.1.0",
"axios": "^0.18.0",
"babel-eslint": "^8.2.6",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.24.1",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"eslint": "^4.19.1",
"file-loader": "^2.0.0",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"url-loader": "^1.1.1"
},
"dependencies": {
"#types/recompose": "^0.27.0",
"antd": "^3.8.2",
"concurrently": "^4.0.1",
"cors": "^2.8.4",
"datatables.net": "^1.10.19",
"es6-promise": "^4.2.5",
"font-awesome": "^4.7.0",
"google-map-react": "^1.1.0",
"google-maps-react": "^2.0.2",
"isomorphic-fetch": "^2.2.1",
"jwt-auth": "^2.0.1",
"jwt-decode": "^2.2.0",
"react-bootstrap": "^0.32.4",
"react-bootstrap-sweetalert": "^4.4.1",
"react-bootstrap-table": "^4.3.1",
"react-bootstrap-table-next": "^1.2.1",
"react-bootstrap-table2-paginator": "^1.0.3",
"react-bootstrap-table2-toolkit": "^1.1.1",
"react-bs-notifier": "^5.0.0",
"react-filter-search": "^1.0.8",
"react-geolocated": "^2.4.0",
"react-geolocation": "^1.0.4",
"react-google-maps": "^9.4.5",
"react-js-pagination": "^3.0.2",
"react-quill": "^1.3.1",
"react-recaptcha": "^2.3.10",
"react-redux": "^5.0.7",
"react-responsive-data-table": "^1.0.4",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-s-alert": "^1.4.1",
"react-search-input": "^0.11.3",
"routes": "^2.1.0",
"sweetalert": "^2.1.0",
"sweetalert-react": "^0.4.11",
"sweetalert2": "^7.28.4"
}
}
Here's my webpack.config.js
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const package = require('./package.json')
const LIBRARY_NAME = 'fuse'
const VERSION = package.version
const AUTHOR = package.author
const HOMEPAGE = package.homepage
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin
const env = process.env.WEBPACK_ENV
let copyright = fs.readFileSync('COPYRIGHT.txt', 'UTF8')
let outputFile
let plugins = [
new webpack.BannerPlugin({
banner: copyright
.replace('{VERSION}', `v${VERSION}`)
.replace('{AUTHOR_URL}', `${AUTHOR.url}`)
.replace('{HOMEPAGE}', `${HOMEPAGE}`),
entryOnly: true
})
]
if (env === 'build') {
plugins.push(new UglifyJsPlugin({ minimize: true }))
outputFile = `${LIBRARY_NAME}.min.js`
} else {
outputFile = `${LIBRARY_NAME}.js`
}
const config = {
entry: __dirname + './src/index.js',
devtool: 'source-map',
entry: './src',
output: {
path: __dirname + '/dist',
filename: outputFile,
library: 'Fuse',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
loaders: [{
test: /(\.js)$/,
loader: 'babel-loader',
exclude: /(node_modules)/
}]
},
plugins: plugins
}
module.exports = config
When I browse the page look this
after i npm run build it look like this..
npm run build
is missed in the script in package.json.
If you want you deploy npm run prod.
Or you can run npm run watch to see for code changes in real time, but it's good to use on local developement.
If you are working on laravel mix project, you need to set your apache config.
open file/etc/apache2/sites-available/000-default.conf and then
write your own root directory path
DocumentRoot /var/www/<your directory>/public
Next, change you .htacces file : open up /var/www/mmc1/public/.htaccess
write the following at the top
DirectoryIndex index.php
Now, we need to make your server recognize the .htaccess configuration
Go to /etc/apache2/apache2.conf and change
AllowOverride None into AllowOverride All
<Directory /var/www/<your dir>/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
On your terminal,
sudo a2enmod rewrite //rewrite module enable
sudo service restart apache2 //restart your server
And it would be work well...