I get module not found error when using bun

    Problem Description

    When using bun, you might encounter an error like this:

    bash
    Cannot find package 'intlayer' from '/workspace/packages/@intlayer/config/dist/cjs/utils/ESMxCJSHelpers.cjs' undefined
    

    Reason

    Intlayer use require internally. And bun scope the require function to resolve only the packages of the @intlayer/config package, instead of the whole project.

    Solution

    Provide the require function in the configuration

    ts
    const config: IntlayerConfig = {
      build: {
        require,
      },
    };
    
    export default config;
    
    next.config.ts
    import { withIntlayer } from "next-intlayer/server";
    
    const configuration = withIntlayer({
      require,
    });
    
    export default configuration;