Require is not defined react-router-sitemap - javascript

According to the official documentation here the sitemap-builder.js file should look like this:
require('babel-register');
const router = require('./router').default;
const Sitemap = require('../').default;
(
new Sitemap(router)
.build('http://my-site.ru')
.save('./sitemap.xml')
);
However, when I run npm run sitemap I get an error that require is undefined.
I have read that you cant use require in react so I tried import statements ex.
import Sitemap from 'react-router-sitemap'
But here I get another error that Sitemap is not a constructor
My sitemap-builder.js:
import pkg from 'react-router-sitemap';
const { Sitemap } = pkg;
const router = [
{
path: '/',
},
{
path: '/pravila',
},
{
path: '/users/:uid',
},
{
path: '/users/:uid/podcats/:pid',
},
{
path: '/post',
},
{
path: '/myprofile',
}
]
(
new Sitemap(router)
.build('https://example.com/')
.save('./sitemap.xml')
);
My package.json:
{
"name": "podcasts",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"firebase": "^7.14.4",
"react": "^16.13.1",
"react-collapsible": "^2.8.0",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^16.13.1",
"react-infinite-scroll-component": "^5.0.5",
"react-infinite-scroller": "^1.2.4",
"react-player": "^2.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"react-video-thumbnail": "^0.1.3",
"reactjs-popup": "^1.5.0"
},
"type": "module",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"predeploy": "npm run build",
"deploy": "firebase build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"sitemap": "babel-node src/sitemap/generator.js"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "^7.10.2",
"#babel/node": "^7.10.1",
"#babel/preset-env": "^7.10.2",
"#babel/register": "^7.10.1",
"react-router-sitemap": "^1.2.0"
}
}

You need the default of it you can destructure the default property like this:
const { default: Sitemap } = pkg

Related

Module build failed (from ./node_modules/craco-less/node_modules/less-loader/dist/cjs.js):

Here is the package.json from my project, I've ran npm install.
{
"name": "myProject",
"version": "0.1.0",
"private": true,
"dependencies": {
"#ant-design/icons": "^4.0.0",
"#babel/core": "^7.9.0",
"#babel/preset-env": "^7.20.2",
"#craco/craco": "^7.0.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"antd": "^4.8.1",
"axios": "^0.19.2",
"babel-preset-react-app": "^9.1.2",
"connected-react-router": "^6.8.0",
"craco-less": "^2.0.0",
"i18next": "^19.7.0",
"react": "^16.14.0",
"react-dom": "^16.13.1",
"react-i18next": "^11.7.2",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^5.0.1",
"redux-persist": "^6.0.0",
"redux-saga": "^1.1.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "craco eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"babel-loader": "^8.1.0",
"less-loader": "^11.1.0"
}
}
after ran npm start, I've got this error
Compiled with problems:X
ERROR in ./src/index.less (./node_modules/css-loader/dist/cjs.js??> > ruleSet[1].rules[1].oneOf[9].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[9].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[1].oneOf[9].use[3]!./node_modules/craco-less/node_modules/less-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[9].use[4]!./src/index.less)
Module build failed (from ./node_modules/craco-less/node_modules/less-loader/dist/cjs.js):
// ================================================================
.table-size(~'middle', #table-padding-vertical-md, #table-padding-horizontal-md, #table-font-size-md);
^
Operation on an invalid type
Error in /Users/user/audien/node_modules/antd/lib/table/style/size.less (line 53, column 0)
I've tried to lower less-loader to version 5.0.0, but it still doesn't work.
Set math as always in your less options
math: 'always'
In your craco.config.js
const CracoLessPlugin = require('craco-less');
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
math: 'always',
modifyVars: { '#primary-color': '#6b75e3' },
javascriptEnabled: true,
},
},
},
},
],
};

Cannot make a request using proxy in my react app

im trying to use a proxy in my package.json fille like this
{
"name": "type-redux-toolkit",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.12.4",
"#material-ui/icons": "^4.11.3",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.5.2",
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-query": "^3.39.1",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:8800/api/v1" //proxy is here
}
and then making a post request using axios like this
const res = await axios.post("/auth/login", credentials);
console.log(res);
now if i just put the full url in the request it works but i want to use the proxy.
i deleted the package-lock.json file and node_modules folder and restared the app like some people say but nothing

Attempted import error: 'Outlet' is not exported from 'react-router-dom

i'm getting this error Attempted import error: 'Outlet' is not exported from 'react-router-dom
if i comment Outlet it throws Attempted import error: 'Switch' is not exported from 'react-router-dom
my package.json is
{
"name": "react-shoe-store-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.11.2",
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"history": "^5.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router": "^6.0.0-beta.0",
"react-router-dom": "^6.0.0-beta.0",
"react-scripts": "4.0.1",
"react-slick": "^0.27.13",
"slick-carousel": "^1.8.1",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
i have installed react-router-dom v6 but i can't configure this error
I can't find any info about Outlet, but Switch is exported from react-router and not react-router-dom, see here
import { Switch } from "react-router";

Problem with proxy property in package.json (react)

I've added the proxy property in package.json that is pointing to http://localhost:8080/ becouse I want to connect my node.js backend with my react frontend. However after setting this, my react app starts on the port 8080 or on whatever port I set in the proxy in package.json. What I'm doing wrong? I would like to start my react app on port 3000 and leave the port 8080 free for the node backend.
Here is my whole package.json file:
{
"name": "restaurants-portfolio-project",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.20.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongodb": "^3.6.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"react-select": "^3.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"dev:server": "nodemon ./backend/server.js"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:8080/"
}

SyntaxError: ..\node_modules\react-router-native\BackButton.js: Support for the experimental syntax 'classProperties' isn't currently enabled (7:14):

I have a problem with react-router-native in react-native project,
Just enter code here boot with yarn start I have this error in console:
5 |
6 | class BackButton extends React.Component {
> 7 | handleBack = () => {
| ^
8 | if (this.history.index === 0) {
9 | return false; // home screen
10 | } else {
Add #babel/plugin-proposal-class-properties to the 'plugins' section of your Babel config to enable transformation.
I have tried to follow the suggested guide, that is to install .
#babel/plugin-proposal-class-properties
To insert the file .babelrc and babel.config.js in the root, but it didn't work.
My package.json
{
"name": "Project",
"version": "0.1.0",
"private": true,
"dependencies": {
"#mod/common": "1.0.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"#types/jest": "^24.9.1",
"#types/node": "^12.12.47",
"#types/react": "^16.9.41",
"#types/react-dom": "^16.9.8",
"#types/react-router-dom": "^5.1.5",
"http-proxy-middleware": "^1.0.4",
"react": "^16.13.1",
"react-art": "^16.13.1",
"react-dom": "^16.13.1",
"react-multi-lang": "^2.1.1",
"react-native": "^0.62.2",
"react-native-web": "^0.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"sockjs-client": "^1.4.0",
"typescript": "^3.7.5",
"universal-cookie": "^4.0.3"
},
"scripts": {
"start": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.10.4",
"#types/react-native": "^0.62.16",
"cross-env": "^7.0.2"
}
}

Categories