-
-
Notifications
You must be signed in to change notification settings - Fork 879
Description
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:
- 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
boxenwould be a nice way to highlight this information, see this code for an example.
From SyncLinear.com | TRI-1331