These days I’m building several next.js apps and want to share some libraries. In the beginning plain js file without compile just work well. But when it comes to jsx component element with sass component-level module, next.js start to fail.
After several tries, I found a solution:
- Create shared package somewhere
yarn linkto link shared library
next-transpile-moduleto transpile library
# Shared repo
const withTM = require('next-transpile-modules')(['shared'])
You can now use
import awesome_component from 'shared'
in your repository!
Hope this helps you! :)