首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在@nrwl/nextjs monorepo中使用next-transpile-模块时遇到麻烦

在@nrwl/nextjs monorepo中使用next-transpile-模块时遇到麻烦
EN

Stack Overflow用户
提问于 2022-01-29 04:58:22
回答 1查看 1.3K关注 0票数 1

我的理解是,我和其他人一样,掉进了组1

运行nextjs,因此他们希望能够从node_modules导入他们的其他包。

并遇到一个类似于以下内容的错误:

无法从../../node_modules/@waweb/base-ui.theme.brand-definition/dist/brand-definition.module.scss内部导入node_modules CSS模块。阅读更多信息:../../node_modules/@waweb/base-ui.theme.brand-definition/dist/index.js:https://nextjs.org/docs/messages/css-modules-npm位置

正式的解决方案是next-transpile-modules,但是一旦我将任何包添加到模块列表中,我就开始在本地源代码中发现CSS模块中的错误。

代码语言:javascript
运行
复制
../../libs/ui/src/lib/contact.module.css
CSS Modules cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-modules-npm
Location: ../../libs/ui/src/lib/learn-more.tsx

Import trace for requested module:
../../libs/ui/src/lib/learn-more.tsx
../../libs/ui/src/lib/home.tsx
./pages/index.tsx

对于以前工作过的所有组件,都会重复这种情况。

我已经准备好了一个公共回购中的分支机构,它配置了一个完整的ci/cd和木荚 dev env,演示了关键的更改。

让我们假设我试图传输的组件的源位于正确的node_modules dir中,并且我正在使用下面的下一个配置:

代码语言:javascript
运行
复制
// eslint-disable-next-line @typescript-eslint/no-var-requires
const withNx = require('@nrwl/next/plugins/with-nx');
const withPlugins = require('next-compose-plugins');
const withTM = require('next-transpile-modules')(
  [
    '@waweb/base-ui.theme.colors',
    '@waweb/base-ui.theme.color-definition',
    '@waweb/base-ui.theme.size-definition',
    '@waweb/base-ui.theme.shadow-definition',
    '@waweb/base-ui.theme.brand-definition',
    '@waweb/base-ui.theme.theme-provider',
  ],
  { debug: true }
);
const withPWA = require('next-pwa');

/**
 * @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = {
  nx: {
    // Set this to true if you would like to to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: true,
  },
  images: {
    domains: [
      'www.datocms-assets.com',
      'a.storyblok.com',
      'images.ctfassets.net',
      'images.prismic.io',
      'cdn.aglty.io',
      'localhost', // For Strapi
    ],
    imageSizes: [24, 64, 300],
  },
};

const pwaConfig = {};

const plugins = [[withNx], [withPWA, pwaConfig]];

module.exports = withTM(withPlugins([...plugins], nextConfig));

你知道我的装置怎么了吗?

谢谢大家对我做错了什么的想法。

干杯!

编辑

对于一些额外的上下文,我尝试了许多不同的变体,根据调试语句,我最后得到的一个变体(如上面所示)是模块转换实际工作的原因。直到现在,我才报告了实际上是源组件的模块中的错误,而不是node_modules。插件的使用似乎破坏了不相关的功能。

EN

回答 1

Stack Overflow用户

发布于 2022-01-29 08:51:24

我觉得很奇怪你把withPuglins包在withTM里面.

withTM是一个插件,所以我认为它应该是更多的这种格式:

代码语言:javascript
运行
复制
module.exports = withPlugins([
  withTM
], nextConfig);

这似乎是我们在查看文档时所期望的:

https://www.npmjs.com/package/next-transpile-modules

https://www.npmjs.com/package/next-compose-plugins

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

https://stackoverflow.com/questions/70902416

复制
相关文章

相似问题

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