I tried to create a react app and add typescript to it.
But when I run the app, it seems like npm start is not detecting the typescript file and not generating tsconfig.json automatically.
Here is what I did:
1. npx create-react-app my-app
2. cd my-app
3. npm install --save typescript #types/node #types/react #types/react-dom #types/jest
4. rename index and app to tsx file
4. npm start
The error I got:
Module not found: Error: Can't resolve './App' in
'C:\WebDev\threeJs\01-tutorial\src'
I assume it is because it's looking for App.jsx not App.tsx. But I'm not sure what is the reason for that.
Here is some warning I got when npm start:
DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option...
My npm version: 6.14.15
Here is my package.json file:
{
"name": "01-tutorial",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.2",
"#testing-library/react": "^12.1.2",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.4.0",
"#types/node": "^17.0.17",
"#types/react": "^17.0.39",
"#types/react-dom": "^17.0.11",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"typescript": "^4.5.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"
]
}
}
I had the same error, I was in the root folder but my package.json file was a step ahead. I cd into the folder where my package.json file was and it worked for me.
Related
Here is my package.json:
{
"name": "new-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^14.4.3",
"buffer": "^6.0.3",
"dotenv": "^16.0.3",
"guardian-wallet": "^0.0.6-rc.30",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"web-vitals": "^3.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"preinstall": "npx npm-force-resolutions"
},
"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": {
"react-error-overlay": "^6.0.11"
},
"resolutions": {
"//": "See https://github.com/facebook/create-react-app/issues/11773",
"react-error-overlay": "6.0.9"
}
}
My app.js :
import logo from './logo.svg';
import './App.css';
import GuardianWallet from "guardian-wallet";
I have tried many the solutions I came across nothing helped:
I have tried upgrade react-scripts to its latest version.
Tried npm install --save-dev react-error-overlay#6.0.9 --force.
Tried adding resolution.
Deleted node_modules and package.lock.json and then used npm cache clean --force and then
did npm install.
process is a Node.js global; process is not defined in a React application most likely means that you're trying to use an NPM package that was written for Node.js, not a browser environment.
Depending on your specific environment and needs, there are a few approaches you could take to fix it: You could replace the NPM package that you're using with one that's written for browsers, or submit a request or PR to add browser support to the NPM package you're using, or set up polyfills in your bundler (see, e.g., here).
"npm run deploy" not working after trying to deploy my react app to github and getting: ENOENT: no such file or directory, stat 'C:s<path\build>'C:\Users\USER 2021\Desktop\robotfriends>npm run deploy npm WARN config global --global, --local are deprecated. Use --location=global instead.
robotfriends#0.1.0 predeploy
npm run build
npm WARN config global --global, --local are deprecated. Use --location=global instead.
robotfriends#0.1.0 build
react-scripts build
robotfriends#0.1.0 deploy
gh-pages -d build
ENOENT: no such file or directory, stat 'C:\Users\USER 2021\Desktop\robotfriends\build'
here's my Package.json :
{
"homepage": "https://Aligumi.github.io/robotfriends",
"name": "robotfriends",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"tachyons": "^4.12.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"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"
]
},
"devDependencies": {
"gh-pages": "^4.0.0"
}
}
Found the solution my self! :)
I had to run npm run build to create the build folder. Then ran npm run deploy
I have a simple react app that I started recently just to study a few things and suddenly, when I try to run it with:
yarn start
it does not throws any error, just stays like this:
yarn run v1.22.19
warning ..\package.json: No license field
$ react-scripts start
and nothing happens, what should i do?
PS: my complete package.json:
{
"name": "prototype",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^13.0.0",
"#testing-library/user-event": "^13.2.1",
"framer-motion": "^7.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"start": "^5.1.0",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.0"
},
"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"
]
},
"devDependencies": {
"eslint": "^8.21.0"
}
}
As you can see in the error message the path of the package.json file is in the warning:
yarn run v1.22.19
warning ..\package.json: No license field
$ react-scripts start
That double dots ..\ saying that the package.json file is one folder up from where you are running the yarn start command. It could be OUTSIDE the project folder you're working on.
So if you go one directory up you will find another package.json file. Either add "license" field into that package.json file or simply delete the file if you do not need it.
This should solve your problem.
I am trying to make a test component on bit dev, but I fail.
After succesfully:
creating an app - CRA
initializing bit
installing compiler
adding / building / exporting component
I get a warning when I go to bit dev page of a component (which is exported properly, but preview is not loading):
Note: your component has no build task defined!
To consume components using NPM or Yarn you should define a build environment for your components. Learn more.
And therefore I can't then install this component in other project.
Package.json looks like this:
{
"name": "new-one",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"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"
]
},
"bit": {
"env": {
"compiler": "bit.envs/compilers/react#2.0.0"
},
"componentsDefaultDirectory": "components/{name}",
"packageManager": "npm"
}
}
I search and search, but no one seems to have such a problem. Any idea?
Error during installation in another project:
npm ERR! code ENOVERSIONS
npm ERR! No valid versions available for #bit/maciejwira.main.test
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Maciej\AppData\Roaming\npm-cache\_logs\2021-05-15T14_38_51_258Z-debug.log
I have created a new organisation on npm and I am trying to publish my react component as a scoped package so that my team can use the same component in-house in all other apps.
On running npm publish command I am getting the following
npm ERR! code EPRIVATE
npm ERR! This package has been marked as private
npm ERR! Remove the 'private' field from the package.json to publish it.
npm ERR! A complete log of this run can be found in:
my package.json looks like this
{
"name": "my-package-name",
"version": "1.0.0",
"private": true,
"main": "dist/AllExports.js",
"module": "dist/AllExports.js",
"dependencies": {
"#material-ui/core": "^4.11.2",
"#material-ui/icons": "^4.11.2",
"#testing-library/jest-dom": "^5.11.6",
"#testing-library/react": "^11.2.2",
"#testing-library/user-event": "^12.4.0",
"axios": "^0.21.0",
"package1217721": "^1.2.7",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hook-form": "^6.13.0",
"react-redux": "^7.2.2",
"react-scripts": "4.0.1",
"redux": "^4.0.5",
"redux-persist": "^6.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "set NODE_ENV=production && rm -rf dist && mkdir dist && npx babel src/components --out-dir dist",
"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:5000",
"devDependencies": {
"#babel/cli": "^7.12.10",
"#babel/preset-react": "^7.12.10"
}
}
And .babelrc file looks like this
//.babelrc
{
"presets": [
"#babel/preset-react"
]
}
And .npmrc looks like this
registry=http://registry.npmjs.org/
scope=myscopename
#myscopename:registry=http://registry.npmjs.org
And I have also tried
login out and then login in again.
uninstalled node_modules and then re-installed them.
did npm update
cleared npm cache as well
I have solved the issue. I was trying to use .npmrc to set scope but that was not working the way I wanted it to work.
But running the command "npm init --scope=your-scope" did the job. This command rebuilds the package.json file. I was not running the command at the first place because I was not sure if I need to run "npm init" if I already have a package.json in place. And I was afraid that it might reset the dependencies of my package but that is not the case. It keeps the dependencies intact.
Set private field (at 3rd line) in package.json file to false.