我用npm start来启动一个React应用程序,其中package.json中定义了start:
{
"name": "testreactapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-scripts": "1.0.10"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}Run Code Online (Sandbox Code Playgroud)
我现在想停止它,而不关闭终端。我怎么做?
尝试过:npm stop testrectapp,但是会抛出错误,需要脚本
然后尝试:使用脚本“ stop”运行npm run stop:“ pkill --signal SIGINT testreactapp”抛出错误“ pkill无法识别为命令”
编辑:在bash中运行ps显示:
PID PPID PGID WINPID TTY UID STIME COMMAND
6652 1 6652 6652 ? 197612 19:52:49 /usr/bin/mintty
1092 1 1092 1092 ? 197612 Jul 25 /usr/bin/mintty
11092 6652 11092 10060 pty1 197612 …
在一个项目中,我在我的`.babelrc中create-react-app使用@babel/plugin-proposal-optional-chaining
但是,我有这个错误:Module parse failed: Unexpected token (22:16) You may need an appropriate loader to handle this file type.
这是我所有的 babel 依赖项:
{
"dependencies": {
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-json-strings": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.9.5",
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/plugin-transform-async-to-generator": "^7.8.3",
"@babel/plugin-transform-modules-commonjs": "^7.9.0",
"@babel/plugin-transform-react-constant-elements": "^7.9.0",
"@babel/plugin-transform-react-inline-elements": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/polyfill": "^7.8.7",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-inline-react-svg": "^1.1.1"
}
}
Run Code Online (Sandbox Code Playgroud)
为了让它发挥作用,我还需要什么?
打字稿抛出:
除非提供了“--jsx”标志,否则无法使用 JSX。ts(17004)
更改tsconfig.json jsx为 后react-jsx,jsx 工作。yarn start将 tsconfig.jsonreact-jsx再次更改为。
react-scripts 已更新至 4.0.1。
包.json
"dependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"semantic-ui-css": "^2.4.1",
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.9",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint-config-react": "^1.1.7",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"typescript": "^4.1.2"
},
Run Code Online (Sandbox Code Playgroud)
配置文件
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": …Run Code Online (Sandbox Code Playgroud) 我从reactJs App根文件夹执行了npm命令“npm run build”,并在控制台中生成了以下输出的“build”文件夹。
File sizes after gzip:
646.8 KB build\static\js\2.d370d4e1.chunk.js
12.46 KB build\static\js\main.fec451dd.chunk.js
823 B build\static\css\main.fc109ae9.chunk.css
772 B build\static\js\runtime-main.83c3e0c4.js
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
serve -s build
Run Code Online (Sandbox Code Playgroud)
然后我执行命令“serve -s build”并在控制台中得到以下输出。
INFO: Accepting connections at http://localhost:5000
Run Code Online (Sandbox Code Playgroud)
我可以看到所有未在开发人员工具中缩小的 *.tsx 文件。不确定我做错了什么以及为什么下面提到的“js”文件夹中的文件没有缩小。

包.json
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": …Run Code Online (Sandbox Code Playgroud) 我的反应应用程序中不断收到此错误
Compiled with problems: X
ERROR in ./ node_modules / dotenv / lib / main.js 1: 11 - 24
Module not found: Error: Can't resolve 'fs' in 'C: \Users\USER\Desktop\dapps\nefty\node_modules\dotenv\lib'
ERROR in ./ node_modules / dotenv / lib / main.js 3: 13 - 28
Module not found: Error: Can't resolve 'path' in 'C: \Users\USER\Desktop\dapps\nefty\node_modules\dotenv\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module …Run Code Online (Sandbox Code Playgroud) react-scripts build我正在使用纱线在私人打字稿存储库上运行。构建失败并显示以下消息:
yarn build -v
yarn run v1.22.17
$ react-scripts build -v
Creating an optimized production build...
Failed to compile.
TS2322: Type 'string | undefined' is not assignable to type 'string | number | boolean'.
Type 'undefined' is not assignable to type 'string | number | boolean'.
114 | withCredentials: true,
115 | headers: {
> 116 | Authorization: token ? `Bearer ${token}` : undefined,
| ^^^^^^^^^^^^^
117 | },
118 | });
119 |
error Command failed with …Run Code Online (Sandbox Code Playgroud) 我在登录页面上使用了react-tooltip,并将工具提示设置为在鼠标单击时触发。但我想当鼠标离开元素时工具提示消失。我找不到办法做到这一点。

我希望上面显示的工具提示在鼠标离开元素时删除。
这是我使用的 npm 包。https://www.npmjs.com/package/react-tooltip
因此,我已经在全栈React应用程序上工作了几个月。由于某种原因,当我尝试npm run start在命令行上运行时,似乎无处不在,它产生了以下错误;
// npm run start
> pair@0.1.0 start /Users/eden/Documents/GitHub/Pair./pair
> react-scripts start
/Users/eden/Documents/GitHub/Pair./pair/node_modules/react-dev-utils/WebpackDevServerUtils.js:166
compiler.hooks.done.tap('done', async stats => {
^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/eden/Documents/GitHub/Pair./pair/node_modules/react-scripts/scripts/start.js:45:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pair@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! …Run Code Online (Sandbox Code Playgroud)我正在构建一个 Docker 映像,用于使用单独的 React 应用程序进行调试Dockerfile
FROM node:11-alpine\n\nCOPY package.json .\nCOPY yarn.lock .\nRUN yarn install\n\nCOPY public/ ./public/\nCOPY src/ ./src/\n\nEXPOSE 3000\nCMD yarn run start\nRun Code Online (Sandbox Code Playgroud)\n\n和package.json
{\n "name": "yarn-start-in-kubernetes",\n "version": "0.1.0",\n "private": true,\n "dependencies": {\n "react": "^16.8.1",\n "react-dom": "^16.8.1",\n "react-scripts": "2.1.3",\n "babel-loader": "8.0.4"\n },\n "scripts": {\n "start": "react-scripts start",\n "build": "react-scripts build",\n "test": "react-scripts test",\n "eject": "react-scripts eject"\n },\n "browserslist": [\n ">0.2%",\n "not dead",\n "not ie <= 11",\n "not op_mini all"\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\n\n当图像与 一起使用时,它会按预期启动开发服务器docker run。升级至
我想在同一台服务器上运行后端服务器和前端。因此,我构建了前端并提供了构建路径,但这不起作用。
这是我的 npm 脚本文件。
{
"name": "nasa-fe",
"version": "1.0.0",
"private": true,
"dependencies": {
"arwes": "^1.0.0-alpha.5",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "BUILD_PATH=../server/public 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"
]
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行构建命令时,它显示“BUILD_PATH”未被识别为内部或外部命令。我该如何解决。
react-scripts ×10
reactjs ×9
javascript ×3
webpack ×2
yarnpkg ×2
babel-loader ×1
babeljs ×1
docker ×1
dotenv ×1
jsx ×1
minify ×1
node.js ×1
npm ×1
npm-build ×1
npm-start ×1
pkill ×1
tooltip ×1
typescript ×1