Nik*_*vic 15 typescript reactjs monorepo next.js pnpm
我有一个带有 TurbeRepo monorepo 的 PNPM,使用了这个模板。在这个 monorepo 中,我有一个使用ui-shared
包(本地共享代码,实际上不是 npm 包)的 NextJS 应用程序。
它ui-shared
是按照类似的方式制作的,但我的包裹当然要大得多。index.ts
使用导出所有组件和共享实用程序的a 。
构建时ui-shared
它成功构建,但是当我构建 Nextjs 应用程序时,ui-shared
构建失败,因为它无法解析tsconfig
. 因此,经过几天的侦探工作,我成功地找出了我认为的问题所在。当构建下一个应用程序时,它也会构建 ,ui-shared
但会失败,因为现在的路径基于 nextjs 而不是库本身。我不确定这是原因,但我相信是这样,而且我不知道如何解决这个问题
(我将指的是共享包或包ui-shared
)
构建共享包成功
\nESM \xe2\x9a\xa1\xef\xb8\x8f Build success in 112ms\nESM dist/index.mjs 220.69 KB\nDTS Build start\nDTS \xe2\x9a\xa1\xef\xb8\x8f Build success in 4792ms\n
Run Code Online (Sandbox Code Playgroud)\npackage.json 的部分内容
\n "main": "./src/index.ts",\n "module": "./dist/index.mjs",\n "types": "./src/index.ts",\n "scripts": {\n "lint": "eslint *.ts*",\n "build": "tsup ./src/index.ts --format esm,cjs --dts --external react",\n "dev": "tsup ./src/index.ts --format esm,cjs --watch --dts --external react"\n },\n
Run Code Online (Sandbox Code Playgroud)\n包的 tsconfig
\n{\n "extends": "tsconfig/react-library.json",\n "compilerOptions": {\n "baseUrl": ".",\n "resolveJsonModule": true,\n "allowJs": true,\n "paths": {\n "@/*": ["src/*"]\n }\n },\n "include": ["**/*.ts", "**/*.tsx"],\n "exclude": ["dist", "build", "node_modules"]\n}\n
Run Code Online (Sandbox Code Playgroud)\n当我运行 NextJs 应用程序的构建时,出现此错误
\npnpm build\n\n> @company/business-frontend@1.0.0 build /work/company/monorepo/apps/business\n> next build\n\nSee more info here: https://nextjs.org/docs/messages/invalid-next-config\ninfo - Skipping linting\ninfo - Checking validity of types .Failed to compile.\n\n../../packages/ui-shared/src/components/AnimatedLoadingMedia.tsx:9:23\nType error: Cannot find module \'@/utils/clsxm\' or its corresponding type declarations.\n\n 7 | } from "react";\n 8 | \n> 9 | import { clsxm } from "@/utils/clsxm";\n | ^\n 10 | \n 11 | type AnimatedLoadingMediaProps = {\n 12 | isVideo: boolean;\n\n> Build error occurred\nError: Call retries were exceeded\n at ChildProcessWorker.initialize (/work/company/monorepo/node_modules/.pnpm/next@12.2.4_twoewwu6sg7cdf3ao6njtbftne/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)\n at ChildProcessWorker._onExit (/work/company/monorepo/node_modules/.pnpm/next@12.2.4_twoewwu6sg7cdf3ao6njtbftne/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)\n at ChildProcess.emit (node:events:390:28)\n at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) {\n type: \'WorkerError\'\n}\n
Run Code Online (Sandbox Code Playgroud)\nNextjs 应用程序tsconfig
{\n "extends": "tsconfig/nextjs.json",\n "compilerOptions": {\n "lib": [\n "dom",\n "dom.iterable",\n "esnext"\n ],\n "allowJs": true,\n "baseUrl": ".",\n "module": "esnext",\n "paths": {\n "@/*": ["src/*"],\n "@": ["src"],\n "@public/*": ["public/*"],\n "@public": ["public"]\n },\n },\n "include": [\n "next-env.d.ts",\n "**/*.ts",\n "**/*.tsx"\n ],\n "exclude": [\n "node_modules"\n ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n不知何故,该库在从 nextjs 构建时必须解析自己的路径。或者更好的是,库应该在自己的范围内构建,而 nextjs 应该只使用输出。我不知道它是否可以这样工作
\n我尝试添加第三方库,但喜欢tsc-alias
tsconfig-path
等等。但构建一直失败。我试图查看并以某种方式阻止 nextjs 构建软件包,但我找不到方法
归档时间: |
|
查看次数: |
3753 次 |
最近记录: |