首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用另一个库的Turborepo库--您可能需要一个适当的加载程序来处理此文件类型。

使用另一个库的Turborepo库--您可能需要一个适当的加载程序来处理此文件类型。
EN

Stack Overflow用户
提问于 2022-01-31 09:44:05
回答 1查看 2.5K关注 0票数 7

复制应用程序:https://github.com/uriklar/turborepo-lib-dep-lib-repro

我正在使用Turborepo的基本示例(nextjs应用程序+ ui库)

我想添加一个额外的ui库,并让我的ui库依赖于它。

代码语言:javascript
复制
// packages/ui/Button.tsx
import * as React from "react";
import { Button as AnotherButton} from "anotherui"
export const Button = () => {
  return <><button>Boop</button><AnotherButton/></>;
};

我在包目录中创建了anotherui库,并将它添加为ui的依赖项,如下所示:

代码语言:javascript
复制
{
  "name": "ui",
  "version": "0.0.0",
  "main": "./index.tsx",
  "types": "./index.tsx",
  "license": "MIT",
  "dependencies": {
    "anotherui": "workspace:*"
  },
  "devDependencies": {
    "@types/react": "^17.0.37",
    "@types/react-dom": "^17.0.11",
    "tsconfig": "workspace:*",
    "config": "workspace:*",
    "typescript": "^4.5.3"
  }
}

当我试图构建web应用程序(它从ui中消耗Button )时,我得到了以下错误:

代码语言:javascript
复制
web:build: Failed to compile.
web:build: 
web:build: ../../packages/anotherui/Button.tsx
web:build: Module parse failed: Unexpected token (3:9)
web:build: 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
web:build: | import * as React from "react";
web:build: | export const Button = () => {
web:build: >   return <button>Boop</button>;
web:build: | };
web:build: | 
web:build: 
web:build: Import trace for requested module:
web:build: ../../packages/anotherui/index.tsx
web:build: ../../packages/ui/Button.tsx
web:build: ../../packages/ui/index.tsx
web:build: ./pages/index.tsx
web:build: 

我的问题是:

是否有可能让一个库依赖于来自同一个monorepo的另一个库?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-31 11:37:03

找到了解决办法。它实际上与Next.js有关。

Turborepo已经使用了一个名为“next-transpile- module”的模块,在我的next.config.js文件中,我已经有了以下一行:

代码语言:javascript
复制
const withTM = require("next-transpile-modules")(["ui"]);

所以我把"anotherui"添加到数组中,它起作用了

票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70923887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档