Skip to content
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

ESM support? #63

Open
H01001000 opened this issue Dec 22, 2023 · 13 comments · May be fixed by #66
Open

ESM support? #63

H01001000 opened this issue Dec 22, 2023 · 13 comments · May be fixed by #66

Comments

@H01001000
Copy link

H01001000 commented Dec 22, 2023

Hello, it is not mentioned in the README, but I wonder does it supports outputting ESM module?

@Cauen
Copy link
Owner

Cauen commented Dec 22, 2023

Hi @H01001000
I don't know if I understand your issue correctly
Has Commonjs been generated for you?

@H01001000
Copy link
Author

Mainly about importing, esm need import extension, where input and builder file I can manually add .js at back, but for example utils and object.base don’t have import extension

@Cauen
Copy link
Owner

Cauen commented Dec 23, 2023

You are needing to replace imports with -.js ?

For example:
import { defineMutation, defineMutationFunction, defineMutationPrismaObject } from '../../utils';
to
import { defineMutation, defineMutationFunction, defineMutationPrismaObject } from '../../utils.js';

?

Although I don't understand exactly why, if this is the case perhaps you could use the configs.global.replacer setting to define a function for this

@H01001000
Copy link
Author

@Cauen
Copy link
Owner

Cauen commented Dec 26, 2023

@H01001000 If I understand correctly the way your project is configured, you need the .ts at the end of each import, right?
Does the replacer solve your case?

@joshuaavalon
Copy link

joshuaavalon commented Dec 27, 2023

@Cauen In simple words,

ESM can works with

// Same with TypeScript targeting ESM
import { } from "./script.js"
import { } from "./dir/index.js"

CommonJS can works with both

const { } = require("./script");
const { } = require("./script.js");
const { } = require("./dir");
const { } = require("./dir/index.js");
// TypeScript target CJS
import { } from "./script"
import { } from "./script.js"
import { } from "./dir"
import { } from "./dir/index.js"

@H01001000
Copy link
Author

H01001000 commented Dec 27, 2023

@Cauen sorry for the late reply, it should
Besides it seems that because this repo's target is commonJS, an explicit .cjs extension is needed for pothos.config.xxx

for now, I did is generate it as a separate package with type commonJS, and import it to main pkg

p.s. is type checking possible? tsc with skipLibCheck: false results in run out heap or run forever. there also seems some type error

@Cauen
Copy link
Owner

Cauen commented Dec 28, 2023

Our lib today generates typescript code, right?
I can't quite understand how these extensions cause any problems in your project.

Could you send me some minimal example of the problem you have there?

In the develop branch, i've created an example with dev, build and start commands
https://github.com/Cauen/prisma-generator-pothos-codegen/blob/develop/examples/inputs-simple-sqlite/package.json

Is the problem you face with the build?

@H01001000
Copy link
Author

@Cauen MRE: add "type": "module" to package.json

@Cauen
Copy link
Owner

Cauen commented Jan 10, 2024

Hi @H01001000
Can you please propose the solution you need as a PR?

@H01001000
Copy link
Author

sure, btw what yarn version you using? it seem the yarn is not up to date, want we pr it?

@Cauen
Copy link
Owner

Cauen commented Jan 10, 2024

Feel free to update it :)

My version: 1.22.21

@H01001000 H01001000 linked a pull request Jan 11, 2024 that will close this issue
@H01001000
Copy link
Author

H01001000 commented Jan 11, 2024

@Cauen btw I found out that when simple is false, tsc runs out of the heap when compiling my input.ts file. Is it possible to split the input file for each model?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants