我使用 create-react-app test 创建了一个名为文件夹的测试,在成功创建文件夹后,在执行 npm start 时出现此错误
Failed to compile.
./src/index.js
Module not found: Can't resolve 'react' in 'C:\Users\USER\Desktop\test\src'
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "test",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-scripts": "2.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试删除yarn.lock 文件然后安装yarn,但错误未修复。
我正在使用 Create-React-App 开发渐进式 Web 应用程序,当我部署到 Github Pages 时,我得到了 android-chrome-192x192.png 的 404 错误。清单似乎是从“myName.github.io/”而不是“myName.github.io/myProject/”请求它。当我在文件路径中添加项目名称时,我的开发服务器上出现错误,提示图像不存在!所有其他图标都工作正常,问题似乎仅与 192x192 png 有关。如果有人遇到同样的问题,我将不胜感激,非常感谢!
这是该网站的实时版本,有错误:https://brose55.github.io/robofriends/
这是使用 Create-React-App 制作并部署到 Github Pages 的 PWA。我尝试更改文件路径,但没有任何效果。
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-384x384.png",
"sizes": "512x512",
"type": "image/png"
}
],
Run Code Online (Sandbox Code Playgroud)
预期请求来自 ...github.io/robofriends,但实际上来自 ...github.io/
我正在使用 CRA2 来构建我的项目。有一些地方有 css import,比如
import 'common.css'
Run Code Online (Sandbox Code Playgroud)
或库 CSS,例如
import 'librabry/dist/lib.min.css'
Run Code Online (Sandbox Code Playgroud)
我希望它们作为内联标签包含在内,而不是创建 css 文件,并且对于 WebTool Audit,它们是渲染阻止样式表。
如何导入样式表文件并将其作为内联标记使用 create React app 移动?
TLDR:我如何制作一个 create-react-app,它有一个按钮,将“按下按钮”记录到客户端控制台,并将“客户端按下按钮”记录到服务器控制台?
上下文:作为练习,我决定执行一个简单的任务,即在客户端上单击该按钮时,将记录到服务器控制台“客户端现在执行的任务”。我很快发现这是一种方式,远远超出了我的理解,而且我的应用程序是以 create-react-app 方式构建的,而且我通过“npm start”运行它,这严重限制了我对应用程序上发生的事情的控制。服务器端。我尝试了一些非常丑陋的技巧来让它工作,但我无法在不丢失应用程序其他地方的一些功能的情况下做到这一点。
我正在我的 React 应用程序中测试 Firebase Cloud Messaging 功能,该功能是通过 create-react-app 引导的。请注意,我已经正确初始化了 firebase(包括服务器端的 admin SDK),并且我的客户端部署在 https 上。到目前为止我所做的是:
const messaging = firebase.messaging();
messaging
.requestPermission()
.then(() => {
console.log("Permission granted!");
})
.catch(() => {
console.log("Permission denied!");
});
messaging.onMessage(payload => {
console.log("onMessage: ", payload);
});
Run Code Online (Sandbox Code Playgroud)
importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js");
var config = {
messagingSenderId: <messageID hidden>
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
Run Code Online (Sandbox Code Playgroud)
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("../firebase-messaging-sw.js")
.then(function(registration) {
console.log("Registration …Run Code Online (Sandbox Code Playgroud) 我决定将Material Ui React添加到我的应用程序中。我打算最少使用这个。到目前为止我在一个地方使用它
import TextField from "@material-ui/core/TextField";
render() {return <TextField ... />
Run Code Online (Sandbox Code Playgroud)
我使用默认的 CRA webpack 配置,我的假设是,我不使用的库中的任何内容都不会添加到我的包中。但是,当我使用捆绑分析器时,我看到了这一点。
Create-React-App 是否像我想象的那样不支持死代码的树摇动,或者我做错了什么。
我正在遵循使用 Create-React-App 创建基本 Chrome 扩展的教程(此处找到教程: https: //medium.com/@gilfink/building-a-chrome-extension-using-react-c5bfe45aaf36)
运行 create-react-app my-app 命令后,我用教程代码(如下)替换了 public 文件夹的 manifest.json 文件中自动生成的代码,然后在 public 文件夹中放置了一个 128x128 的图像,名为 logo-small。 png,在清单文件中正确引用了该文件。
我运行了 npm run build 命令,然后打开 Chrome 扩展页面来加载解压的扩展,选择构建文件夹(构建命令将公共文件夹的内容放入构建文件夹中,因此清单和 png 都位于同一位置)。但是,我收到以下错误:
无法加载扩展图标“logo-small.png”。无法加载清单。
我不确定是什么原因造成的,因为我完全按照指示进行操作。有谁知道问题可能是什么?您需要我提供其他信息才能辨别吗?
Manifest.json代码:
{
"manifest_version": 2,
"name": "testapp",
"description": "This extension is a starting point to create a real Chrome extension",
"version": "0.0.1",
"browser_action": {
"default_popup": "index.html",
"default_title": "Open the popup"
},
"icons": {
"16": "logo-small.png",
"48": "logo-small.png",
"128": "logo-small.png"
},
"permissions": [
]
}
Run Code Online (Sandbox Code Playgroud) 我希望打字稿错误显示为警告,但不会导致我的开发服务器崩溃。我能够通过设置.env文件来为 eslint 做到这一点ESLINT_NO_DEV_ERRORS=true。
有等效的打字稿吗?
对于原型设计阶段来说,这确实会适得其反。
这个答案表明:
{
"compilerOptions": {
...
strict: false
}
)
Run Code Online (Sandbox Code Playgroud)
但这还配置了许多其他东西(即没有没有隐式任何)
谢谢!
基本上就是这个。我都尝试过
npm init react-app my-app
Run Code Online (Sandbox Code Playgroud)
和
npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
我总是收到这样的消息:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: @babel/core@7.12.3
npm ERR! node_modules/@babel/core
npm ERR! @babel/core@"7.12.3" from react-scripts@4.0.3
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"*" from the root project
npm ERR! @babel/core@"^7.12.3" from @svgr/webpack@5.5.0
npm ERR! node_modules/@svgr/webpack
npm ERR! @svgr/webpack@"5.5.0" from react-scripts@4.0.3
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"*" from the root project
npm ERR! 9 more (babel-jest, babel-loader, ...)
npm ERR!
npm ERR! …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×7
typescript ×2
craco ×1
css ×1
firebase ×1
github-pages ×1
lighthouse ×1
node.js ×1
npm ×1
terminal ×1
ts-nameof ×1
webpack ×1