我正在尝试构建一个带有 2 个入口点的 React 应用程序,一个用于应用程序,一个用于管理面板。
我从 Create React App V2 开始,并关注这个 gitHub 问题线程https://github.com/facebook/create-react-app/issues/1084和本教程http://imshuai.com/create-react-app -多个入口点/。
我正在尝试移植从 CRA V1 添加多个入口点的说明以在 V2 中工作,但我想我遗漏了一些东西。
弹出 CRA 后,这些是我更改/添加到 path.js 的路径:
module.exports = {
appBuild: resolveApp('build/app'),
appPublic: resolveApp('public/app'),
appHtml: resolveApp('public/app/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/app'),
appSrc: resolveApp('src'),
adminIndexJs: resolveModule(resolveApp, 'src/admin'),
adminSrc: resolveApp('src'),
adminPublic: resolveApp('public/admin'),
adminHtml: resolveApp('public/admin/index.html'),
};
Run Code Online (Sandbox Code Playgroud)
我已将这些入口点添加到 webpack:
entry: {
app: [
isEnvDevelopment &&
require.resolve('react-dev-utils/webpackHotDevClient'),
paths.appIndexJs,
].filter(Boolean),
admin: [
isEnvDevelopment &&
require.resolve('react-dev-utils/webpackHotDevClient'),
paths.adminIndexJs,
].filter(Boolean)
},
output: {
path: isEnvProduction ? paths.appBuild : undefined, …Run Code Online (Sandbox Code Playgroud) 我在jest:24.9.0没有任何配置的情况下使用,从 create-react-app 全局安装。在这些文件中,我使用了 es6 模块。使用时没有错误"test": "react-scripts test"
但是,当我开始使用jestwith 时,"test": "jest --config jest.config.js",我看到以下错误。
FAIL src/configuration/notifications.test.js
? Test suite failed to run
/var/www/management/node/src/configuration/notifications.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import notifications from './notifications';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Run Code Online (Sandbox Code Playgroud) 这是 cra 的全新安装,在节点 13.11.0 上运行打字稿模板,尝试运行 npm start 时出现错误
TypeScript error in D:/Projects/personal-site/node_modules/@types/testing-library__react/node_modules/pretty-format/build/index.d.ts(7,13):
'=' expected. TS1005
5 | * LICENSE file in the root directory of this source tree.
6 | */
> 7 | import type * as PrettyFormat from './types';
| ^
8 | /**
9 | * Returns a presentation string of your `val` object
10 | * @param val any potential JavaScript object```
Run Code Online (Sandbox Code Playgroud) 我正在尝试在非弹出模式下的 create-react-app 中实现 TypeScript 代码共享,但我遇到了臭名昭著的限制,即src不允许在外部导入:
You attempted to import ../../common/src/lib.ts which falls outside of the project src/ directory. [...]
对于非 TypeScript 的情况,这里已被询问并回答,但我无法获得任何使用 TypeScript 的解决方案。具体而言,所提出的解决方案存在的问题是:
设置baseDir在ts-config.json:在这里创建反应的应用程序内抱怨:你的项目baseUrl只能被设置为src或node_modules。Create React App 目前不支持其他值。
基于 react-app-rewired 的方法:更有前途。禁用ModuleScopePlugin让我过去了“在 src 之外尝试导入”错误,但现在的问题是打字稿文件的加载器无法正常运行:
我已经验证它.ts本身没问题:./src从那里复制并导入它工作正常。
我还增加了../../common/src文件夹添加到includes列表中ts-config.json。
我的猜测是 webpack 加载器配置以某种方式有一个规则,可以防止 TypeScript 加载器转译与其预期路径模式不匹配的文件。如何使用 react-app-rewired 解决这个问题?
符号链接源也不起作用——同样的问题。可能是因为 webpack 在内部解析符号链接并在正常加载器规则不适用的路径中看到文件。
基于弹出的解决方案:我现在不想弹出,但我尝试过,基本上又遇到了同样的问题。
我还发现了其他听起来相关但没有回答问题的问题:
我正在关注https://tailwindcss.com/docs/guides/create-react-app上关于在 React 项目中设置 Tailwind 的文档。我一直在按照这些步骤操作,但是当我到达应该运行npx tailwindcss init以生成tailwind.config.js文件的部分时,出现以下错误:
Cannot find module 'autoprefixer'
Require stack:
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli\commands\build.js
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli\commands\index.js
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli\main.js
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli.js
Run Code Online (Sandbox Code Playgroud)
我检查autoprefixer了我的node_modules文件夹中是否有并尝试重新安装它,但我遇到了同样的错误。在我的package.json,我有以下内容:
...
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
...
Run Code Online (Sandbox Code Playgroud)
根据文档。我的craco.config.js文件如下:
module.exports = {
style: {
postcss: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
},
}
Run Code Online (Sandbox Code Playgroud)
再次,根据文档。我也试过重新安装@craco/craco软件包无济于事,所以在这一点上我被卡住了。任何帮助,将不胜感激。
我正在 VS Code 中开发一个 React 应用程序。我使用 create-react-app 进行设置。我可以毫无问题地运行该项目npm start。当我尝试使用 Vercel 发布项目时,出现错误:
已经尝试删除node_modules并npm install再次尝试。
Error! Command "npm run build" exited with 1
Error! Check your logs at https://...
Run Code Online (Sandbox Code Playgroud)
您可以看到以下日志:
13:55:05.231 Retrieving list of deployment files...
13:55:06.975 Downloading 32 deployment files...
13:55:09.142 Analyzing source code...
13:55:11.289 Installing build runtime...
13:55:15.911 Build runtime installed: 4622.485ms
13:55:20.151 Looking up build cache...
13:55:21.237 Build cache not found
13:55:22.615 Detected package.json
13:55:22.616 Installing dependencies...
13:55:58.492 > core-js@2.6.12 postinstall /vercel/path0/node_modules/babel-runtime/node_modules/core-js
13:55:58.492 > node …Run Code Online (Sandbox Code Playgroud) Jest、create-react-app 和 typescript 的奇怪错误。
今晚 Jest 开始无法正确导入我的“./ProcessStore”模块。该模块是我的测试导入的内容的传递依赖项。
我看到的错误是我导入的内容未定义。
当我执行import * as what from "./ProcessStore"并记录(什么)时,它会打印所有导出,但值未定义。就像{default: undefined, ResourceChange: undefined}导出的两个类一样。它应该是{default: <a class>, ResourceChange: <a class>}。
这只是一个文件。所有其他文件都有效。
当我使用 npm start 时,它起作用了 --- 这只是一个玩笑问题。
另外,如果我将损坏的文件重命名为./ProcessStore2,它也可以工作。
我尝试过./node_modules/jest --clearCache,但没有帮助。
如果相关的话,我通常使用craco。暂时切换回反应脚本并没有帮助。
我正在使用react-scripts 4.0.3(最新版本)。
到底是怎么回事?我该如何解决这个愚蠢的问题?
我使用 CRA 创建了一个打字稿应用程序,代码如下:
import { ReactComponent as Search } from './search.svg'
Run Code Online (Sandbox Code Playgroud)
它运行良好,现在我想将此代码剥离到 npm 包(库)中。我通过首先再次运行 CRA,然后删除所有看起来不相关的内容(例如公共文件夹)来创建此包。一个简化版本/dist如下所示:
esm/
icon/
index.d.ts
index.js
index.d.ts
index.js
Run Code Online (Sandbox Code Playgroud)
这是原文icon/index.ts:
/// <reference types="react-scripts" />
import { ReactComponent as Search } from './search.svg'
export const Icons = {
Search,
}
Run Code Online (Sandbox Code Playgroud)
这是编译后的icon/index.d.ts:
/// <reference types="react" /> <-- Changed for some reason??
export declare const Icons: {
Search: import("react").FunctionComponent<import("react").SVGProps<SVGSVGElement> & {
title?: string | undefined;
}>;
};
Run Code Online (Sandbox Code Playgroud)
当我尝试运行使用该库的应用程序时,出现以下错误:
../dist/esm/common/icon/index.js Attempted import error:
'ReactComponent' is not …Run Code Online (Sandbox Code Playgroud) 在 StackOverflow 中找不到任何相关问题。
所以,在盒子组件中,sx道具正在发生变化,比如说
<Box
sx={{
display: 'flex',
flexDirection: 'column',
height: '100%'
}}
>
Run Code Online (Sandbox Code Playgroud)
到
<div class="MuiBox-root MuiBox-root-371"/>
Run Code Online (Sandbox Code Playgroud)
但它不会在其他组件中发生变化,例如ListSubheader
<ListSubheader
disableGutters
disableSticky
sx={{
color: 'text.primary',
fontSize: '0.75rem',
lineHeight: 2.5,
fontWeight: 700,
textTransform: 'uppercase'
}}
>
Run Code Online (Sandbox Code Playgroud)
正在转变为
<li class="MuiListSubheader-root" sx="[object Object]">Manage</li>
Run Code Online (Sandbox Code Playgroud)
我正在使用 create-react-app 和 Material-UI 5,这是我的 package.json
由于某种原因,我的sxprop 没有转换为类名。的屏幕截图
有什么提示可能配置不正确吗?不确定要提供什么所有信息。
在 下创建新项目时create-react-app,您会立即收到有关postcss.
npm 报告的问题:https ://www.npmjs.com/advisories/1693
相关的未决问题可以在这里找到:
该问题已在 上修补postcss v8.2.10,但在创建新项目时仍然存在,因为react-scripts尚未升级依赖项。
所以,我的问题是我无法再运行构建,因为它们由于漏洞而失败。
由于我迫不及待地等待他们修补它以继续处理我的东西(他们似乎从一年前就意识到了这一点),是否有一些解决方法可以用来解决它?
我尝试添加一个postcss分辨率package.json:
"resolutions": {
"postcss": "^8.2.10"
},
Run Code Online (Sandbox Code Playgroud)
但这并没有让我失望。
任何的想法?
create-react-app ×10
reactjs ×10
typescript ×4
javascript ×3
jestjs ×2
webpack ×2
material-ui ×1
npx ×1
postcss ×1
tailwind-css ×1
vercel ×1