在我的应用程序(基于 create-react-app 的 React)的源代码中,我使用了这样的 env 变量:process.env.REACT_APP_API_URL它们存储在我的.env.*文件中。
但是当我在 Cypress 下运行相同的应用程序时,process.env对象是空的。当 React 应用程序在 Cypress 下运行时,如何提供这些变量以在 React 应用程序中使用?
我知道我可以设置 Cypress env 变量,但这不是我想要的 - 这是一个不同的范围。
我目前有一个 monorepo,其中有两个 (+) 使用纱线工作区的包:
root
/packages
/common
/web
...
root/package.json
...
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"**"
],
},
Run Code Online (Sandbox Code Playgroud)
web是一个带有 typescript 模板的普通 create-react-app。我有一些TS的代码common我想在使用web,但似乎CRA不支持编译的代码之外src,给我一个错误,当我尝试进口来自common于web:
../common/state/user/actions.ts 4:66
Module parse failed: Unexpected token (4:66)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import { UpdateUserParams } from './reducer';
|
> export const login = …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的团队创建一个自定义 cra 模板文件以供使用,但一直遇到一个问题,即我在运行npx create-react-app test-app --template my-custom-template.
internal/modules/cjs/loader.js:796
throw err;
^
Error: Cannot find module 'cra-template-my-custom-template'
Require stack:
- C:\Users\user\Desktop\cra-test-app\test-app\node_modules\react-scripts\scripts\init.js
- C:\Users\user\Desktop\cra-test-app\test-app\[eval]
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.resolve (internal/modules/cjs/helpers.js:80:19)
at module.exports (C:\Users\user\Desktop\cra-test-app\test-app\node_modules\react-scripts\scripts\init.js:110:13)
at [eval]:3:14
at Script.runInThisContext (vm.js:116:20)
at Object.runInThisContext (vm.js:306:38)
at Object.<anonymous> ([eval]-wrapper:9:26)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at evalScript (internal/process/execution.js:80:25)
at internal/main/eval_string.js:23:3 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\user\\Desktop\\cra-test-app\\test-app\\node_modules\\react-scripts\\scripts\\init.js',
'C:\\Users\\user\\Desktop\\cra-test-app\\test-app\\[eval]'
]
}
Run Code Online (Sandbox Code Playgroud)
模板本身目前相当简单,我认为这里的问题可能是我们的团队对某些内部包(它们是模板中的依赖项)使用了私有提要。此私有提要设置为使用 npm 作为上游提要。
我尝试使用该--template file:../path/to/template方法在本地测试模板并将模板发布到我们的内部提要。我可以使用 npm install 安装该软件包,因此该软件包肯定会在注册表中找到。
我还尝试根据其他一些建议刷新 npm 缓存并卸载 create-react-app。
我是否必须将模板发布到公共 npm 注册表才能使其工作?还是我错过了其他东西? …
我正在开发一个由别人构建的项目。我知道它是由 create-react-app 引导的,因为它在 README.md 中这么说。
不过,我不确定它是否已被弹出。有很多帖子教你如何实际弹出它,但我一开始就找不到检查它的方法。任何帮助表示赞赏!
我正在开发一个用 制作的反应应用程序create-react-app,每当我启动该应用程序时,我都会收到此错误:
./node_modules/scrambles/dist/esm/scrambles.js 37:39
Module parse failed: Unexpected token (37:39)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
| async function getWorker() {
> const url = outsideStrategy.url.esm ?? outsideStrategy.url.cjs;
| const workerInstantiator = outsideStrategy.workerInstantiator.esm ?? outsideStrategy.workerInstantiator.cjs;
| let worker;
Run Code Online (Sandbox Code Playgroud)
这是我的依赖项package.json:
"dependencies": {
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@types/node": "^15.3.0",
"bulma": "^0.9.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": …Run Code Online (Sandbox Code Playgroud) 我在使用 create-react-app 创建的项目中运行纱线,但收到此错误:
Exit code: 1
Command: start /B node compile.js & node compile.js
Arguments:
Directory: uber-web/node_modules/coa
Output:
/bin/sh: 1: start: not found
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'uber-web/node_modules/coa/compile.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
Run Code Online (Sandbox Code Playgroud)
我已经卸载了所有 .lock 和 node_module 文件夹,但它仍然不起作用。
我有一个用 create React app 制作的有趣项目。我想将同一应用程序转换为浏览器扩展。这个想法迫使我将该项目设为单一存储库。因为在这两个应用程序中,我将使用相同的组件、钩子、提供程序等。
我不想使用 Lerna 或 Yarn 工作区。而且,这将是我的第一个单一仓库。我想开始使用 Turborepo。但是,我无法想象如何让它以良好的方式工作。
我的目标文件夹结构如下
我会将包文件夹中的 monorepo 依赖项导入到 apps 文件夹中存在的 apps 中。
例如;
import { useExampleHook } from '@projectname/hooks'
import { ExampleComponent } from '@projectname/components'
Run Code Online (Sandbox Code Playgroud)
如果您除了 Turborepo 之外还有其他解决方案,请随时告诉我。NPM 工作区也是一个可以接受的解决方案。但是,turborepo 由于性能更好而具有优先权。
预先感谢您的时间和答复
我正在使用 React 创建一个应用程序,它运行良好npm start,但是当我尝试构建该应用程序时,显示以下错误。
PS D:\ ****\ **\*\profile> npm run build
> profile@0.1.0 build
> react-scripts build
D:\ ****\ **\profile\node_modules\react-scripts\config\webpack.config.js:664
new MiniCssExtractPlugin({
^
TypeError: MiniCssExtractPlugin is not a constructor
at module.exports (D:\Documents\Project\React\profile\node_modules\react-scripts\config\webpack.config.js:664:9)
at Object.<anonymous> (D:\Documents\Project\React\profile\node_modules\react-scripts\scripts\build.js:58:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Run Code Online (Sandbox Code Playgroud)
我在用着
| 包裹名字 | 版本 |
|---|---|
| 节点 | 16.13.2 |
| 新项目管理 | 8.1.2 |
| 恩克斯 | 8.1.2 |
这是我的package.json文件。
{
"name": "profile",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": …Run Code Online (Sandbox Code Playgroud) node.js npm reactjs create-react-app mini-css-extract-plugin
我们目前正在开发一个小型应用程序,它只渲染外部 React 组件(因为它是外部npm install组件)。此应用程序的目的是获取一些 JSON 配置并将其作为 prop 传递给该组件以演示其用法。
该应用程序是由 create-react-app 创建的,它对脚手架应用程序的唯一更改是 index.tsx 和 App.tsx 文件的内容。嗯,公共目录中还添加了两个 JSON 文件。
现在的问题是,这个项目可以在我同事的机器上编译并运行,但不能在我的机器上运行。之后npm ci我npm start得到以下信息:
Failed to compile.
Module not found: Error: You attempted to import /home/newlukai/story/app/node_modules/react-refresh/runtime.js 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 project's node_modules/.
assets by path static/js/*.js 4.81 MiB
asset static/js/bundle.js 4.8 …Run Code Online (Sandbox Code Playgroud) 我们希望我们的项目使用\xc2\xa0 react-scripts v 5,并且根据\xc2\xa0 craco维护者最近的评论,支持最新版本CRA的新版本不会如果有的话,很快就会推出(除了 alpha 版本)。
\n我们的 craco.config 并没有做那么繁重的工作 - 我们用它来让 webpack 忽略\xc2\xa0 config \xc2\xa0files,\xc2\xa0限制 moment 使用的时区数据,并为 antd 转译 .less文件xc2\xa0(我们不打算永远使用 antd,但现在我们的应用程序中有它们的一些组件)。
\n我很好奇,现在 \xc2\xa0craco\xc2\xa0 正在走 \xc2\xa0意大利小镇的路,其他人在做什么?
\ncreate-react-app ×10
reactjs ×7
monorepo ×2
node.js ×2
craco ×1
cypress ×1
javascript ×1
npm ×1
turborepo ×1
typescript ×1
webpack ×1
yarnpkg ×1