ricokahler / next-plugin-preval

Pre-evaluate async functions during builds and import them like JSON
MIT License
257 stars 13 forks source link

ES6 module system not supported. #122

Open Jeremboo opened 8 months ago

Jeremboo commented 8 months ago

Hi,

My project is setup with a next.config.mjs which use the ES module system instead of CommomJS.

And the project doesn't look to work with ES6:

import createNextPluginPreval from 'next-plugin-preval/config'

...

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

import createNextPluginPreval from 'next-plugin-preval' looks to exists but is just a [Function (anonymous)] who does nothing.

Maybe should you just place the config.js into the dist/ folder ? I can do a PR if you want.

rickdrumond commented 4 months ago

:wave: Can confirm this is still an issue. I was able to work around it by wrapping the require in a CJS file:

// prevalWrapper.cjs

const createNextPluginPreval = require('next-plugin-preval/config');
const withNextPluginPreval = createNextPluginPreval();

module.exports = withNextPluginPreval;

Then importing the wrapper:

// next.config.mjs

import withNextPluginPreval from './prevalWrapper.cjs';

const nextConfig = { /* options */ };

export default withNextPluginPreval(nextConfig);