-
Notifications
You must be signed in to change notification settings - Fork 325
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
Drop CJS support #1155
Comments
It looks like there's a PR pending to fix it: evanw/esbuild#2067 |
Vite appears to have just merged a workaround for the ESBuild issue above. |
I was looking at going through the codebase and adding all the exact file extensions to address issue 1 above, but I think I'm running into an issue here: Take this export from export {useShop} from './foundation/useShop'; If we want to add the complete file extension so that it's an actual file extension: // TS error: An import path cannot end with a '.ts' extension. Consider importing './foundation/useShop/index.js' instead. ts(2691)
export {useShop} from './foundation/useShop/index.ts'; So we can't end the file extension with Ok, so what if we end it in // "./foundation/useShop/index.js" is not found. eslint[node/no-missing-import](https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-missing-import.md)
export {useShop} from './foundation/useShop/index.js'; ESLint isn't happy about the fact that you're trying to import a non-existent file, which is quite reasonable to be honest. I explored this because I wanted to see if we could address issue 1 without using an experimental flag, but the solution seems to be either use the flag, or disable ESLint's error checking for this type of error so that TS can have its way. 🤷 |
@frehner Thanks for trying that! Yeah, I think we will need to disable this error in ESLint. I don't like using The experimental flag will be removed at some point so we should not rely on it...
|
I actually don't mind using |
But what if those index files are removed? That's been a common discussion, especially in the framework code. |
I'm not a fan of the file extension |
Agreed, I don't think anyone likes it. But it must be done that way, sadly. |
Currently, we are compiling Hydrogen to both CJS and ESM. It would be much simpler and faster to use only ESM.
In
tsconfig.cjs.json
we explicitly includesrc/framework
to be compiled to CJS. However, the whole project ends up being compiled to CJS because insrc/framework
we are importing types from other folders (and TSC follows imports). This has two issues:import.meta
(cc @cartogram )We need CJS at the moment because Vite compiles "import" statements in
vite.config.js
to "require" in projects (user apps) that don't have"type": "module"
in package.json. Therefore, everything that is imported invite.config.js
(plugins) needs to be in CJS.If we want to use ESM only, we would need to add
"type": "module"
to both Hydrogen package and Hydrogen apps. In this scenario, Vite would not use "require" invite.config.js
. However, this has two problems:--experimental-specifier-resolution=node
when running Vite.The text was updated successfully, but these errors were encountered: