gpt4 book ai didi

next.js - 在 webpack build (turborepo) 中包含本地包

转载 作者:行者123 更新时间:2023-12-05 02:36:14 26 4
gpt4 key购买 nike

我在使用 turborepo 的“monorepo”中有两个包 uiapp

我有带有 .tsx 文件的 ui 仓库,它没有被构建,它是 package.json main 是一个 typescript 文件。

但是,当运行 nextjs 时,我在从 ui 主文件导入时遇到错误。

是否可以从 nextjs 的角度包含这个 node_module?查看 config.module.rule 时,我找不到 typescript 文件的任何规则。我不确定 nextjs 文件的 typescript 是如何配置的。

最佳答案

turbo-repo 示例在应用程序中使用 next-transpile-modules 获取 Next 来转译这些没有构建步骤的包依赖项:

// in next.config.js
const withTM = require("next-transpile-modules")(["ui"]);

module.exports = withTM({
reactStrictMode: true,
});

来自 this article Turbo Repo 的创建者 Jared Palmer:

[To] do this, this package can then be used without project references or a TypeScript build step (either via tsc or esbuild etc) as long as you adhere to 2 rules:

  1. The consuming application of an internal package must transpile and typecheck it.
  2. You should never publish an internal package to NPM....

**Next.js

If you use Next.js, you can satisfy these constraints with the next-transpile-modules plugin which will tell Next.js to run certain dependencies through its Webpack/Babel/TypeScript pipelines.

因此,请确保您满足前面摘录中概述的限制条件。由于您正在使用 Next,请检查您的 next.config.js 并确认您正在使用 next-transpile-modules 作为您的内部依赖项。

关于next.js - 在 webpack build (turborepo) 中包含本地包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70342151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com