我使用 React.jsx 创建了一个页面,当我输入 npm start 时,页面打开了 index.jsx。但是,我删除了 index.html 然后将其恢复为“ public ”,从那时起我的页面不再打开 index.jsx,但现在它打开 index.html (所以结果是一个白页,当我写 hello < /h1> 改变.我想知道是否有解决这个问题的方法...... 我的json包如果有用的话:
{
"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",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"react-router-dom": "^6.10.0",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start-build": "npm run start & npm run build",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"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": {
"autoprefixer": "^10.4.14",
"gh-pages": "^5.0.0",
"postcss": "^8.4.21",
"tailwindcss": "^3.3.1"
}
}
我试过删除node_modules文件和package-lock.json文件,然后用npm install重新安装,还是不行
如果您想在 React 应用程序中运行 npm start 时打开 index.jsx 而不是 index.html,则需要确保 package.json 文件中的启动脚本指向正确的文件。
打开你的 package.json 文件。 找到“脚本”对象。 查找“start”属性并确保它指向您的 index.jsx 文件。 例如,如果您的 index.jsx 文件位于名为 src 的文件夹中,则“start”属性应如下所示:
"scripts": {
"start": "react-scripts start src/index.jsx",
// other scripts
}
保存更改并尝试再次运行 npm start。这应该以 index.jsx 作为入口点打开你的 React 应用