Actually i have a project which i need to include in Next JS as a module. So basically i am trying to use it via npm link
, I am successfully able to add that module into my next JS repo as a component. But it is breaking because of webpack loaders. Should i need to add all the loaders necessary in next JS? what is better way to achieve this ?
Import modules into next js
3.8k Views Asked by Amit At
2
There are 2 best solutions below
0

With the new update of Next, js supports ES Modules and URL Imports.
Starting with Next.js 11.1, we added experimental support for ES modules being prioritized over CommonJS modules. In Next.js 12, this is now the default. Importing NPM modules that only provide CommonJS is still supported.
https://nextjs.org/blog/next-12#es-modules-support-and-url-imports
By default Next.js doesn't compiles dependencies located at
node_modules
.You should use
next-transpile-modules
in order to instruct it to compile specific libs.