当尝试运行测试时,Jest 会抛出遇到的意外令牌错误。我正在使用 ky http,这显然会导致问题并且不会被转译。
\n\n Test suite failed to run\n\n Jest encountered an unexpected token\n\n This usually means that you are trying to import a file which Jest cannot parse, e.g. it\'s not plain JavaScript.\n\n By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".\n\n Here\'s what you can do:\n \xe2\x80\xa2 To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.\n \xe2\x80\xa2 If you need …Run Code Online (Sandbox Code Playgroud) 我有一个学生提交的代码包含许多class(非 className)属性。例如:
import React, { Component } from "react";
class Images extends Component {
render() {
return (
<div class="gallery">
<div class="zoom"><img src="foo.jpg" alt="Foo"/></div>
<div class="zoom"><img src="bar.jpg" alt="Bar"/></div>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
但不知怎的,他的代码可以工作,并生成实际的 HTMLclass属性。我什至尝试删除一行,以确保代码确实被使用,但果然相应的行在输出中被删除了。
我不明白这是如何运作的。学生使用了create-react-app,它使用该react-scripts库来编译/运行该网站,但我找不到任何提及任何一个转换class为className:
https://facebook.github.io/create-react-app/
https://github.com/facebook/create-react-app/tree/master/packages/react-scripts
谁能解释一下这个巫术?;)
PS相关库版本:
"jsx": "^0.9.89",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"@babel/preset-react": "^7.0.0",
Run Code Online (Sandbox Code Playgroud) 我不确定这是否是create-react-app或 的问题yarn。
我正在尝试使用create-react-app. yarn它似乎在幕后使用来获取依赖项,但yarn忽略了自己的注册表配置设置并尝试直接从https://registry.yarnpkg.com/下载包。
这是我尝试使用时的输出create-react-app。您可以在最后看到yarn忽略注册表配置设置:
$ npx create-react-app@2.1.2 my-app --verbose --registry "http://myownregistry:1234/"
npm info it worked if it ends with ok
npm info using npm@6.4.1
npm info using node@v10.13.0
npm timing npm Completed in 153ms
npm info ok
npx: installed 63 in 72.714s
Creating a new React app in C:\work\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
yarn …Run Code Online (Sandbox Code Playgroud) 我在 Amazon EC2 实例上托管一个 create-react-app,每次部署新版本的 Web 应用程序(即 run )时yarn react-scripts build,都会有几分钟的停机时间,直到应用程序构建完成。build/该应用程序由 直接从文件夹提供服务serve ./build -s。
我考虑过从不同的文件夹提供服务,例如deployed/,仅在文件夹中的构建build/完成后才复制到该文件夹。这应该可以最大限度地减少停机时间。但我没有发现其他人推荐这种做法,如果真的推荐的话,我猜这react-scripts build会做类似的开箱即用的事情,以防止提供部分构建的资产。
所以我的问题是,在服务器上构建资产时是否有某种标准方法可以防止停机。
我使用create-react-app 16 。["react": "^16.8.4", "react-scripts": "^2.1.8"] \n我阅读了Ben Schwarz使用Chrome 开发工具分析 React 性能的博客:\n https://building.calibreapp.com/debugging-react-performance-with-react-16-and-chrome-devtools-c90698a522ad \n他建议使用source-maps导出你的 JS 。\n当他进行表演时跟踪,然后单击“用户计时”部分中的给定反应组件,特定组件信息显示在“自下而上”部分中,并在右侧带有**指向源代码**的蓝色链接。当我单击 React 组件时,此链接不会显示。当我单击“评估脚本”等组件时,右侧会显示蓝色链接。
\n\n源映射不应该在开发中与create-react-app 16一起“开箱即用”吗?\n我只想在开发中使用Chrome 开发工具进行源映射。源映射在 Chrome 浏览器中激活。我错过了什么?\n提前谢谢
\n\nPS:由于我还没有获得 10 点声望点,所以我\xc2\xb4m 不打算使用屏幕截图,这在这种情况下让事情变得不太容易。不过,我希望我能够充分解释我的问题。
\nperformance-testing google-chrome-devtools source-maps reactjs create-react-app
当我在cmd中执行命令时:
npx create-react-app my-app --typescript
Run Code Online (Sandbox Code Playgroud)
看起来应用程序将是打字稿,但是当我在 VS-code 中打开文件夹时,我释放 src 文件夹中的所有文件都带有.js扩展名,而不是.ts(.tsx)扩展名..我尝试通过 cmd 创建应用程序(管理员模式) )但没用,没有改变。我还尝试使用命令:
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
Run Code Online (Sandbox Code Playgroud)
依然没有。
没有错误。应用程序的工作方式类似于标准的 React+js 应用程序。
我有一个 create-react-app 项目,使用绝对导入和 css 模块(scss)。我正在尝试定义自定义字体,但导入未得到解决。
尝试了文档中建议的所有内容。
我的文件夹结构
jsconfig.json
public
src
L assets
L fonts
L impact.ttf
L index.js
L index.scss
Run Code Online (Sandbox Code Playgroud)
在我的index.scss中
@font-face {
font-family: 'impact';
src: url(./assets/fonts/impact.ttf) format('ttf');
}
Run Code Online (Sandbox Code Playgroud)
我的 jsconfig.json (用于绝对导入)
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Run Code Online (Sandbox Code Playgroud)
import './index.scss'我的 index.js在文件顶部导入。当我尝试编译此代码时,我的组件抛出一个错误,指出无法解析字体文件...
Module not found: Can't resolve './assets/fonts/brush.ttf' in '/Users/xxx/project/src/containers/mycomponent'
Run Code Online (Sandbox Code Playgroud)
还可以使用node-sassscss 文件来工作。这个想不出来了...
我正在尝试使用react-docgen-typescript-loaderTypeScript Props 在 Storybook 中生成道具文档,但它不会将任何内容填充到插件中withInfo。
我正在使用 create-react-app 的 TypeScript 风格,并且遵循多种不同的配置方法,.storybook/webpack.config.js但似乎没有任何效果。
这是我当前的配置:
module.exports = ({ config, mode }) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
}
},
require.resolve("react-docgen-typescript-loader"),
]
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
};
Run Code Online (Sandbox Code Playgroud)
import { configure } from '@storybook/react';
// automatically import all files ending in *.stories.js
const req = require.context('../', true, /.stories.tsx$/);
function loadStories() {
req.keys().forEach(filename => …Run Code Online (Sandbox Code Playgroud) 所以我尝试运行reactjs官方教程并使用第一行代码:
npx create-react-app react-tutorial
Run Code Online (Sandbox Code Playgroud)
...我收到以下错误:
npx: installed 91 in 12.692s
Creating a new React app in /home/foo/projects/react-tutorial.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
yarn add v1.12.3
[1/4] Resolving packages...
warning react-scripts > fsevents@2.0.6: Please update: there are crash fixes
[2/4] Fetching packages...
[-----] 1/1297Missing dependencies in package.json
Run Code Online (Sandbox Code Playgroud)
我在其他地方阅读了一些清理或强制清理 npm 缓存的内容,但这也不起作用:
npm cache clean --force
Run Code Online (Sandbox Code Playgroud)
我在 ubuntu 上运行最新的节点 (10.16.0) 我也尝试过 8.*
我目前正在开发我的第一个 MERN 应用程序。我在将我的应用程序推送到 GitHub 时遇到一些问题。我的应用程序文件结构如下:
\n\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80myApp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80server.js\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80connection.js\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80controls\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80models\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80client <-- create-react-app folder\nRun Code Online (Sandbox Code Playgroud)\n\n我知道使用 create-react-app 也会运行git init。因此,如果我尝试在 GitHub 上获取完整的应用程序,我将在 git 存储库中获得一个 git 存储库:
有没有一种方法可以从 create-react-app 中删除 git 并将我的整个应用程序推送到一个存储库?
\n\n谢谢
\ncreate-react-app ×10
reactjs ×8
typescript ×2
babeljs ×1
fonts ×1
git ×1
github ×1
jestjs ×1
jsx ×1
sass ×1
source-maps ×1
storybook ×1
yarnpkg ×1