我有具有以下文件结构的 monorepo(纱线工作区):
??? client (workspace @client)
? ??? package.json
? ??? tsconfig.json (extended tsconfig)
??? server (workspace @server)
? ??? getData.ts
? ??? package.json
? ??? tsconfig.json (extended tsconfig)
??? shared
? ??? sanitizeData.ts
??? package.json (monorepo root)
??? tsconfig.json (base tsconfig)
Run Code Online (Sandbox Code Playgroud)
我想从shared/sanitizeData.tsin使用函数server/getData.ts
我尝试paths从 Typescript 中使用,根据文档,它看起来很简单,但我做错了:
error TS2307: Cannot find module '@shared/sanitizeData'.
Run Code Online (Sandbox Code Playgroud)
server/tsconfig.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "../",
"outDir": "build",
"paths": {
"@shared/*": ["shared/*"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
server/getData.js:
??? …Run Code Online (Sandbox Code Playgroud) 我在将 Yarn Workspaces monorepo 移植到 TypeScript 时遇到问题。在 monorepo 的先前工作版本中,moduleA可以从moduleB.
新移植的代码尝试同样的事情......
/* monorepo/packages/moduleA/src/helpers/misc.ts */
export const someHelper = () => console.log('hello world')
Run Code Online (Sandbox Code Playgroud)
/* monorepo/packages/moduleB/src/index.ts */
import {someHelper} from 'moduleA/src/helpers/index.js'
Run Code Online (Sandbox Code Playgroud)
这会产生错误:
错误 [ERR_MODULE_NOT_FOUND]:找不到从 monorepo/packages/moduleB/lib/index.js 导入的模块“monorepo/node_modules/moduleA/src/helpers/misc.js”
我的两个包的 TsConfig:
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"composite": true,
"outDir": "lib",
"rootDir": "src",
"allowJs": true,
"esModuleInterop": true,
"moduleResolution": "node",
"module": "es6"
},
"include": ["src"],
}
Run Code Online (Sandbox Code Playgroud)
并添加了moduleB包的配置:
"references": [
{
"path": "../moduleA"
}
]
Run Code Online (Sandbox Code Playgroud)
请注意,我正在moduleB使用tsc …
我已经尝试这个9个小时了。我已经浏览了我在互联网上可以找到的每一个 github 问题、博客、链接,并尝试了一百多次。最后我把它发布在这里。
我正在使用yarn berry 3.0.2。我做到了yarn dlx create-react-app ./ --template typescript。到目前为止,一切都很好。然后我安装了yarn vscode sdk以与零安装PNP一起使用。并添加了反应+打字稿+爱彼迎配置。Linting 也可以工作,但只能从命令行进行。我只是无法启用 eslint vscode 扩展。我总是得到
o use ESLint please install eslint by running yarn add eslint in the workspace folder client
or globally using 'yarn global add eslint'. You need to reopen the workspace after installing eslint.
Alternatively you can disable ESLint for the workspace folder client by executing the 'Disable ESLint' command.
Run Code Online (Sandbox Code Playgroud)
现在我已经安装了 eslint 和所有其他东西。我认为问题是由于纱线即插即用而没有node_modules文件夹。我怎样才能以某种方式配置 vscode eslint 扩展来工作。
谢谢。
typescript reactjs visual-studio-code yarnpkg yarn-workspaces
yarn install --focus使用 Yarn Workspaces,可以非常轻松地在包目录之一内使用单个工作区安装包。
但是,有时我希望能够仅安装顶级package.json. 我在整个存储库中运行 linter,并且我希望能够安装 linting 依赖项,而无需安装工作区中所需的每个包。
我怎样才能做到这一点?
升级到yarn 3后,当我运行时yarn install,分辨率将从文件中删除package.json并添加到yarn.lock文件中。
package.json使用yarn 3时,分辨率不应该驻留在其中吗?
我正在关注纱线安装文档。当我跑步时corepack prepare yarn@stable --activate,我得到了Usage Error: Invalid package manager specification in CLI arguments; expected a semver version。有人知道怎么回事吗?
我用来nodemon观察 TypeScript Node.JS代码库中的文件更改。当检测到更改时,esbuild和esbuild-register用于将代码转换为 CommonJS 文件,然后应用程序重新启动。
该应用程序是带有纱线工作区的monorepo 的一部分。我在应用程序中使用共享包中的一些代码。
我如何才能nodemon自动监视同一工作区中的依赖项以进行更改并触发重新启动?
我的解决方法是添加in中所有使用的链接依赖项的相对路径,但这需要我在添加本地链接依赖项时手动编辑配置。watchnodemon.json
nodemon.json
{
"exec": "node -r esbuild-register",
"ext": "ts,json",
"watch": [
"src",
"../../packages/logger/src",
"../../packages/helpers/src"
],
"ignore": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
package.json
{
"dependencies": {
"@app/logger": "*",
"@app/helpers": "*"
}
}
Run Code Online (Sandbox Code Playgroud) 我安装了node v16.13.0,npm v8.1.0 java版本1.8.0_211,我想我也安装了yarn,但尝试使用yarn global add expo-cli安装expo我得到:
yarn : File C:\Program Files\nodejs\yarn.ps1 cannot be loaded. The file C:\Program Files\nodejs\yarn.ps1 is not
digitally signed. You cannot run this script on the current system. For more information about running scripts and
setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yarn global add expo-cli
+ ~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Run Code Online (Sandbox Code Playgroud)
然后我再次尝试安装yarn,但现在我100%无法获取它:
PS C:\Users\user> npm install -g yarn
changed 1 package, and audited 2 …Run Code Online (Sandbox Code Playgroud) 我们刚刚开始在我们的两个主要项目中使用 monorepo 和纱线工作区。一个最初是基于 Angular 11 构建的,另一个是在 React 中构建的。
我们设置了纱线工作区,并且在一个项目(Angular)上一切都运行得很好。反应方虽然接错了babel-loader。
这是当前的文件夹结构:
root
|--package.json
|--node_modules
| |--"babel-loader": "8.1.0"
|--hub
| |--package.json
| |--node_modules
| |-- <no babel-loader here>
|--platform
| |--package.json
| |--node_modules
| |--"babel-loader": "8.2.3"
...
Run Code Online (Sandbox Code Playgroud)
根package.json:
{
"private": true,
"workspaces": [
"platform",
"hub",
"shared"
]
}
Run Code Online (Sandbox Code Playgroud)
中心package.json
{
"name": "hub",
"version": "0.1.0",
"license": "MIT",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest --maxConcurrency=2 --maxWorkers=2",
"eslint": "eslint 'src/app/**/*.{js,jsx,ts,tsx}'",
"eslint:fix": "eslint --fix 'src/app/**/*.{js,jsx,ts,tsx}'", …Run Code Online (Sandbox Code Playgroud) 我正在努力创建一个yarn workspace在 React 和 React Native 之间共享代码的方法(一旦完全完成,即将发布博客文章!)。
对我们来说最重要的部分是在两个平台之间共享业务逻辑。在这种情况下我们使用react-query网络请求。
我们为此创建了一个“渲染道具”组件
\nimport { useAllDevices } from "../../queries/devices";\n\nexport interface DeviceListProps {\n devices: any[];\n isLoading: boolean,\n onItemClick?: () => void;\n}\n\nexport interface DeviceItemListProps {\n name: string;\n onItemClick?: () => void;\n}\n\nexport const DeviceListContainer = ({ render }: { render: any }) => {\n const { data, isLoading } = useAllDevices();\n return (\n <>\n {render({ devices: data?.devices, isLoading })}\n </>\n )\n}\nRun Code Online (Sandbox Code Playgroud)\n在哪里useAllDevices有这样的东西:
export const useAllDevices = …Run Code Online (Sandbox Code Playgroud) yarn-workspaces ×10
javascript ×4
node.js ×4
yarnpkg ×4
monorepo ×3
reactjs ×3
typescript ×3
yarn-v2 ×2
angular ×1
installation ×1
nodemon ×1
npm ×1
npm-install ×1
react-native ×1
react-query ×1
tsconfig ×1
yarn-v3 ×1