将模块导入下一个 js

问题描述

实际上我有一个项目,我需要将其作为模块包含在 Next JS 中。所以基本上我试图通过 npm link 使用它,我能够成功地将该模块作为组件添加到我的下一个 JS 存储库中。但由于 webpack 加载器,它正在中断。我是否需要在下一个 JS 中添加所有必需的加载器?实现这一目标的更好方法是什么?

enter image description here

enter image description here

解决方法

默认情况下 Next.js 不编译位于 node_modules 的依赖项。

您应该使用 next-transpile-modules 来指示它编译特定的库。

// next.config.js
const withTM = require('next-transpile-modules')(['somemodule','and-another']);

module.exports = withTM({
  ...regular next config
});