我在这里看到了很多类似的问题,我已经尝试了所有方法,但我不知道为什么仍然没有显示任何内容。
npm install react-app-polyfill
我在 package.json 的生产和开发数组中添加了“ie 11”
将此两行添加import "react-app-polyfill/ie11";
import "react-app-polyfill/stable";到顶部index.js
删除 node_modules 中的 .cache 文件夹
重启应用
但仍然没有在 ie 11 中显示任何内容。
这是我的 package.json
{
"name": "firealarm",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.3",
"@testing-library/user-event": "^7.1.2",
"antd": "^3.26.2",
"axios": "^0.19.0",
"core-js": "^3.6.1",
"cors": "^2.8.5",
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.2.11",
"react": "^16.12.0",
"react-app-polyfill": "^1.0.5",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0"
},
"scripts": {
"start": "set PORT=3006 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": …Run Code Online (Sandbox Code Playgroud) 我使用更新了我的反应项目
npm install --save --save-exact react-scripts@3.3.0
但是当我开始我的反应项目时,我得到了这个......
启动开发服务器...
<--- 最后几次 GC --->
[27403:0x108000000] 53085个MS:扫气2041.3(2049.1) - > 2040.6(2049.4)MB,7.8 / 0.0毫秒(平均亩= 0.242,电流亩= 0.164)分配失败[27403:0x108000000] 53094个MS:扫气2041.8(2049.9 ) -> 2041.2 (2050.1) MB, 7.7 / 0.0 ms (平均 mu = 0.242, 当前 mu = 0.164) 分配失败 [27403:0x108000000] 53101 ms: Scavenge 2042.0.3.05) -205 (20) ms(平均 mu = 0.242,当前 mu = 0.164)分配失败
<--- JS 堆栈跟踪 --->
==== JS 堆栈跟踪 ==========================================
Run Code Online (Sandbox Code Playgroud)0: ExitFrame [pc: 0x100930c99] 1: StubFrame [pc: 0x1008e42a7] Security context: 0x3d30707408a1 <JSObject> 2: SourceMapConsumer_allGeneratedPositionsFor [0x3d307ed12519] [/Users/bob/IdeaProjects/test-client/node_modules/source-map/lib/source-map-consumer.js:~178][pc=0x183302d049b6](this=0x3d30ec3c01a1 ,0x3d303d727d61) …
我使用 create-react-app 创建 react app 并设置如下文件结构:
src/
-index.js
-main.scss
pages/
-somepage.js
-somepage.scss
styles/
-_variables.scss
Run Code Online (Sandbox Code Playgroud)
索引.js
import './main.scss';
...
Run Code Online (Sandbox Code Playgroud)
主文件
@import './styles/variables.scss';
Run Code Online (Sandbox Code Playgroud)
_variables.scss
$primary: #000;
Run Code Online (Sandbox Code Playgroud)
somepage.js
import somepage.scss
Run Code Online (Sandbox Code Playgroud)
somepage.scss
selector {
property: $primary; <-- sass can't find that
}
Run Code Online (Sandbox Code Playgroud)
请问有什么想法吗?谢谢你。
我一直试图解决这个问题太久了。我的目标是从我的 Create React App 应用程序创建一个包。我正在遵循这里广受好评的步骤:
https://github.com/facebook/create-react-app/issues/3365#issuecomment-376546407
我将 dist/build/bundle.min.js 中生成的包包含在 html 中并加载页面。根据网络选项卡正确加载文件内容。
但是没有console.log!该网站只是保持空白。
有任何想法吗?我附上了 bundle.min.js 仅供参考。
谢谢
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),e.exports=n(5)},function(e,t,n){var r=n(2);"string"==typeof r&&(r=[[e.i,r,""]]);n(4)(r,{insert:"head",singleton:!1}),r.locals&&(e.exports=r.locals)},function(e,t,n){(e.exports=n(3)(!1)).push([e.i,"body{margin:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}.App{text-align:center}.App-logo{height:40vmin;pointer-events:none}@media (prefers-reduced-motion:no-preference){.App-logo{-webkit-animation:App-logo-spin 20s linear infinite;animation:App-logo-spin 20s linear infinite}}.App-header{background-color:#282c34;min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;font-size:calc(10px + 2vmin);color:#fff}.App-link{color:#61dafb}@-webkit-keyframes App-logo-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes App-logo-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}",""])},function(e,t,n){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=function(e,t){var …Run Code Online (Sandbox Code Playgroud) 我有如下代码,用于检查是否使用某些参数调用了我的命名函数:
const wrapper = mount(<PromotionsContent {...props} />);
let params = new URLSearchParams();
params.append('page', 0);
params.append('size', '20');
expect(getPromotions).toHaveBeenCalledWith(params);
Run Code Online (Sandbox Code Playgroud)
这里 getPromotions 是一个命名函数,它在测试文件中被正确导入和模拟。这以前运行良好,但在升级我的应用程序以使用最新的 CreateReactApp(使用 React 16.12.0)后,它开始崩溃。我还在调用 getPromotions 之前将参数记录到控制台,我实际上可以看到正确的值,但在测试中它只是打印如下并失败:
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
- {},
+ {},
Number of calls: 1
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,如果我直接使用如下所示的被调用参数,它会起作用:
const wrapper = mount(<PromotionsContent {...props} />);
let params = new URLSearchParams();
params.append('page', 0);
params.append('size', '20');
let calledParams = getPromotions.mock.calls[0][0];
expect(calledParams.get('page')).toEqual ('0');
expect(calledParams.get('size')).toEqual ('20');
Run Code Online (Sandbox Code Playgroud)
请问有什么线索吗?
我在单一回购中有 2 个 CRA 项目 - P1 和 P2。
root/
projects/
p1/
package.json
tsconfig.json
src/
shared/
**/*.ts
p2/
package.json
tsconfig.json
src/
**/*.ts
Run Code Online (Sandbox Code Playgroud)
P1包含一些共享基础设施源文件,我想在P2.
注意:我知道这种方法的缺点和负面影响,但是......
我试过的:
包括P1从P2和导入:
P1 tsconfig.json 修改为
"include": [..., "root/projects/p1/src/shared/**/*.ts]
P2 源文件通过相对路径导入 .ts 文件结果:
You attempted to import <path> which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from …Run Code Online (Sandbox Code Playgroud)我正在尝试导入与 D3 库一起使用的 CSV 以在 Create React App 项目中创建图表,但即使 CSV 文件的路径正确,导入文件也会引发“找不到模块”错误。
我有一种感觉,这可能与 CRA 的 Webpack 配置有关,但看起来这是使用文件加载器,所以我不确定问题是什么。数据文件位于 CRA 的 src 目录中。
下面代码中的控制台日志正在以正确的数据运行,这意味着必须正在访问数据。在此之后抛出错误(尽管 CSV 的路径在我的编辑器中带有红色下划线)。
我正在使用 TypeScript,但我认为这与问题无关。
import React from 'react';
import * as d3 from 'd3';
import CSVData from '../data/data.csv';
const BarChart: React.FC = () => {
d3.csv(CSVData).then(res => {
console.log(res);
});
return <div>Test</div>;
};
export default BarChart;
Run Code Online (Sandbox Code Playgroud) 已解决 - 请参阅下面的答案。
可调用函数导致 CORS 错误,如下所示:
从源“ http://localhost:3000 ”获取“ https://us-central1-careerhub-a50a2.cloudfunctions.net/createUser ”的访问权限已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。如果不透明响应满足您的需求,请将请求的模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。
功能代码:
exports.createUser = functions.https.onCall((data, context) => {
const email = data.email
const password = data.password
admin.auth().createUser({
email: email,
emailVerified: false,
password: password
}).then((res) => {
return {
response: res
}
}).catch((err) => {
return {err}
})
})
Run Code Online (Sandbox Code Playgroud)
客户端:
const handleAddUser = () => {
let pswd = passwordGen(7)
const createUser = firebase.functions().httpsCallable('createUser');
createUser({email: email, password: pswd}).then(function(result) {
let res = result.data
console.log(res)
}).catch(function(error) {
console.log(error.code) …Run Code Online (Sandbox Code Playgroud) cors firebase reactjs google-cloud-functions create-react-app
create-react-app这个使用create-react-apptypescript创建的 react 项目将用于显示一些自定义组件,以便在其他项目中重复使用。我的目标是让组件在使用它的代码旁边使用。
如果我无权访问 webpack 配置并且无法使用,我该如何加载文件fs.readFile?
我正在使用 create-react-app 并且我还有一些 ts 和 tsx 文件。在我的 tsconfig 文件(见下文)中,我将 noEmit 设置为 false,因为需要发出 js 文件。但是,每次启动服务器时, noEmit 都会设置为 false 并显示以下消息:
The following changes are being made to your tsconfig.json file:
- compilerOptions.noEmit must be true
Run Code Online (Sandbox Code Playgroud)
当 noEmit 设置为 false 时,应该从我的 ts 文件生成的 js 文件不会生成,这意味着应用程序没有更新。是什么导致了这种行为?有什么办法可以避免吗?或者是为包含 ts 文件的文件夹制作单独的 tsconfig 的唯一选择?
{
"compilerOptions": {
"target": "ES2017",
"module": "esnext",
"lib": [
"dom",
"dom.iterable",
"esnext",
"ES2017"
],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"strictPropertyInitialization": false, …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×6
typescript ×3
cors ×1
css ×1
csv ×1
es6-modules ×1
firebase ×1
javascript ×1
jestjs ×1
node-sass ×1
polyfills ×1
sass ×1
webpack ×1
yarnpkg ×1