martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Support next.config.mjs #255

Closed slavb18 closed 1 year ago

slavb18 commented 2 years ago

Are you trying to transpile a local package or an npm package? If an npm package, which one? next-auth (actual package does not matters)

Describe the bug A clear and concise description of what the bug is (please include logs from your terminal with debug enabled).

Error in console:

[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'fs'

To Reproduce Steps to reproduce the behavior (a reproduction is even better):

Create next.config.mjs

import withTmInitializer from 'next-transpile-modules';
import fs from 'fs';

const withTM = withTmInitializer([
  'next-auth',
]);

const nextConfig = {
  trailingSlash: false,
};

const tmConfig=withTM(nextConfig);
export default tmConfig;

then start app npm run dev

Example project https://github.com/slavb18/hello-world-app

Expected behavior A clear and concise description of what you expected to happen. There should be no error Caching failed for pack: Error: Can't resolve 'fs'

Setup

martpie commented 2 years ago

Hi! 👋

.mjs is now supported for Next.js configs? Did you try with a classic next.config.js just to see if it'd work?

kachkaev commented 2 years ago

.mjs is now supported for Next.js configs?

Yep!

slavb18 commented 2 years ago

Hi! wave

.mjs is now supported for Next.js configs? Did you try with a classic next.config.js just to see if it'd work?

classic next.config.js working:

const withTM = require('next-transpile-modules')([
  'next-auth',
]);
const fs=require('fs');

const nextConfig = {
  trailingSlash: false,
};

module.exports=withTM(nextConfig);

but in my case mjs is required to import es6 module

slavb18 commented 2 years ago

this issue can be fixed? or should I supply additional info ?

martpie commented 2 years ago

Sorry for the silence, I haven't had a look at it yet, but it definitely should be supported!