-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[turborepo] Codegenerator not support ESM #5657
Comments
It works when I use .cjs with jsDoc instead |
This is a known limitation at the moment, we're working to provide full support for ESM dependencies in the future! |
Simply to expand on what @peam1146 mentioned with an example. Go from this, import type { PlopTypes } from '@turbo/gen';
export default function generator(plop: PlopTypes.NodePlopAPI): void {
// ...
} to this, /** @param plop {import('@turbo/gen').PlopTypes.NodePlopAPI} */
module.exports = (plop) => {
// ...
}; And everyone's happy. |
I think this is an important feature as it blocks us from having code generation in |
I was digging into this issue and found out that adding a While this is not merged if anyone stumbles into this you can create the file by hand, including on already existent templates without the need to convert the #typesafety_ftw |
### Description As described by #5657, the default `simple-*` templates creates a template that is broken for `"type": "module"` packages. When digging into this issue I found out that a simple `package.json` with `"type": "commonjs"` solves the problems by telling the runtime to treat the file diferently from the parent package. ### Testing Instructions - Initialize a new monorepo with `"type": "module"` in the `package.json` - on this branch it should now be possible to generate the sample generator (either `js` or `ts`) and not have any errors about the module type. - it should also be possible to run the generator and it should create the file in the project root normally. resolves #5657
### Description As described by vercel#5657, the default `simple-*` templates creates a template that is broken for `"type": "module"` packages. When digging into this issue I found out that a simple `package.json` with `"type": "commonjs"` solves the problems by telling the runtime to treat the file diferently from the parent package. ### Testing Instructions - Initialize a new monorepo with `"type": "module"` in the `package.json` - on this branch it should now be possible to generate the sample generator (either `js` or `ts`) and not have any errors about the module type. - it should also be possible to run the generator and it should create the file in the project root normally. resolves vercel#5657
@tknickman @wesleycoder While this works to let you run the generator file, it doesn't fix the original issue that generators don't support ESM. So if I import an ESM package into one of my generators, it will still complain about require() of ESM module. I think we should re-open this issue OR I can file a new issue if that's preferable |
Why is this issue closed? My entire codebase is in ESM format and this silly workaround with package.json is not a solution. At the very least this should work with a config.cts/config.cjs file. |
AFAIK the support for ESM should come from the underlying plopjs/plop package and turborepo has no way of supporting this on it's own. |
I ended up using plop directly. Turborepo is using version 0.26.0 of |
@paolostyle Caret behaves differently for 0.x.y version ranges. It will never upgrade past 0.26.x @wesleycoder are there any plans to upgrade the version of Plop within Turborepo? I think it might resolve the issues that people like me are having with the way turbo gen handles ESM files 🙏 |
I know how it behaves, that's what I meant by "stuck" and "due to semver", but I suppose I didn't express my thoughts properly, sorry about that. |
What version of Turborepo are you using?
v1.10.9
What package manager are you using / does the bug impact?
Yarn v2/v3 (node_modules linker only)
What operating system are you using?
Mac
Describe the Bug
I got this error when use "type: 'module'" in package.json
Expected Behavior
It should work ...
To Reproduce
use "type: 'module'" in package.json
Reproduction Repo
No response
The text was updated successfully, but these errors were encountered: