Skip to content

[TRI-1334] [TRI-1331] CLI warning if using @trigger.dev/react package with Next.js pages directory #526

@matt-aitken

Description

@matt-aitken

Problem

We add the @trigger.dev/react package when you run npx @trigger.dev/cli@latest init in a Next.js project. The Next.js pages directory has a known issue with ESM modules.

We currently have an open issue but this still isn't great: #331

Solution

Show a clear warning in our CLI init command that gives you instructions on what to do, if you're using Next.js + pages router.

If on Next.js >13.1, add this to next.config file:

const nextConfig = {
  transpilePackages: ["@trigger.dev/react"],
};

module.exports = nextConfig;

If on Next.js <13.1, add this to next.config file:

  1. Install next-transpile-modules package
const withTM = require('next-transpile-modules')(['@trigger.dev/react']); // pass the modules you would like to see transpiled

module.exports = withTM({
  //...existing config object
});

How to

  • It makes most sense to add this to the post-install step.

  • There's already a function to check for pages directory that can be used

    const nextJsDir = await detectPagesOrAppDir(path);
    
  • Here's some code that could potentially be adapted to check the Next.js version. But be careful when checking versions because special characters are used in package.json files, like "^" and "*". So either you should get the actual version installed (not using the package.json) or use a semver package to do the comparison.

  • Drawing a box using boxen would be a nice way to highlight this information, see this code for an example.

From SyncLinear.com | TRI-1331

TRI-1334

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions