-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
TypeScript doesn't work with "type": "module" in package.json #239
Comments
For what it's worth, webpack had the same issue: webpack/webpack-cli#2458 Their fix does not work with postcss, however:
still throws the same error. |
Seems like for now there is no good way to use TS and ESM together. All of them are very dirty (like hacking Node.js with custom loaders). It is better to use If you have any trick in mind, we can review the PR. |
From vitejs/vite#11894: |
@polyzen do you have an idea how to fix it? |
I do not. |
https://tailwindcss.com/blog/tailwindcss-v3-3#esm-and-typescript-support I do not know if this is equivalent, but |
Also use named variables so type-checking works: postcss/postcss#1824 Once the following is resolved a TypeScript config file could be used: postcss/postcss-load-config#239
我认为这是一个bug,为什么还没修复 |
Tailwind uses jiti + sucrase to handle this: https://github.com/tailwindlabs/tailwindcss/blob/master/src/lib/load-config.ts I can create a PR here if the maintainers allow. jiti already comes with babel, so sucrase is only required if you want to increase perf. Also, this issue is similar to #246. Fixing this will close it too. |
@TimothyGu can you check that #246 works on your big repo? |
Thanks for the release |
should use this config |
Running any
postcss-cli
command fails with"type": "module"
inpackage.json
, andpostcss.config.ts
)Details
After support for
.mjs
was added in version 4 of this module, I expected ESM-mode TypeScript to work as well. Unfortunately, it does not.The issue has to do with how TypeScript config files are loaded:
postcss-load-config/src/index.js
Lines 114 to 117 in b8cdab0
Using ts-node
.register()
/require()
with"type": "module"
is simply unsupported. See ts-node documentation.Workaround
The ts-node documentation describes a valid workaround:
Indeed, if I include
in
tsconfig.json
then the error goes away.Error (Logs|Stacks)
https://gist.github.com/TimothyGu/e65fcba3fd759cd6fa2e415ed2047b77#file-readme-md
Reproduction (Code)
See https://gist.github.com/TimothyGu/e65fcba3fd759cd6fa2e415ed2047b77
$ git clone https://gist.github.com/e65fcba3fd759cd6fa2e415ed2047b77.git testdir $ cd testdir $ yarn $ node_modules/.bin/postcss test.css
Environment
postcss-cli 10.0.0
postcss-load-config 4.0.1
see yarn.lock
The text was updated successfully, but these errors were encountered: