-
-
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
Feature Request: support mjs config #230
Comments
Sure. Send PR. |
I found loading esm module is async, it seems it will break sync load config. https://github.com/postcss/postcss-load-config#sync Maybe we can only use mjs in async mode. Is this work as intended? |
We can add |
What should we do about mjs support?😂 |
Sorry, have no idea |
Getting the basic support working shouldn't be hard. With diff --git a/src/index.js b/src/index.js
index db5c40e..56a4538 100644
--- a/src/index.js
+++ b/src/index.js
@@ -81,14 +81,19 @@ const addTypeScriptLoader = (options = {}, loader) => {
`.${moduleName}rc.ts`,
`.${moduleName}rc.js`,
`.${moduleName}rc.cjs`,
+ `.${moduleName}rc.mjs`,
`${moduleName}.config.ts`,
`${moduleName}.config.js`,
- `${moduleName}.config.cjs`
+ `${moduleName}.config.cjs`,
+ `${moduleName}.config.mjs`
],
loaders: {
...options.loaders,
'.yaml': (filepath, content) => yaml.parse(content),
'.yml': (filepath, content) => yaml.parse(content),
+ '.js': (filepath) => import(filepath).then(module => module.default),
+ '.cjs': (filepath) => import(filepath).then(module => module.default),
+ '.mjs': (filepath) => import(filepath).then(module => module.default),
'.ts': loader
}
} But the details are tricky:
|
Hm. We could think about major release. When is Node 12 end of support? |
Node 12 seems to have 2022-04-30 as end of life and Node 10 went EOL on 2021-04-30. |
Is it possible to check |
Probably, but it's a new syntax, not just a function, so it requires some sort of |
Maybe we can check node version |
Can we make PR to play with this approach? |
I created #234, implementing And just a warning: Node often crashes with a Segmentation fault when running the jest tests in that PR. Not sure why, though, maybe jest exposes a Node/V8 Bug?
|
Very strange. On what Node.js versions? |
Node 13, 14, 15, 16 and 17. Strangely, it works on Node 12 ( |
Does it work without Jest? For instance, you can replace |
I think the (seg fault) issue is nodejs/node#35889, apparently is has something to with how jest hooks into the ESM loading process. I could not get it to crash without |
I can ask my junior developers to move |
@michael42 Can you pull changes to your pull request to see the result? |
I just rebased, it seems the crashes are gone, now. I think the biggest issue now is the synchronous loading mode. By preferring Further still, why is |
Yes, we can move to async-only API in next major release |
Great, I just pushed another version that removes the sync API. That made it possible to switch to the All in all, I consider the PR almost complete now. Unfortunately, the coverage dropped below the limit, because of the Node 10 fallback. Not sure if it's worth to add another test for that legacy edge-case, I think excluding that lines from coverage or lowering the limit a bit is more appropriate. |
It is OK to decrease a limit. |
Any update on this? |
Thanks for the ping. I released in it 4.0. We will need to wait for PostCSS runners for the update. |
@ai @michael42 Hi! Thank you for this. What about import autoprefixer from "autoprefixer";
const config = {
plugins: [
autoprefixer,
],
};
export default config; Config above can't be loaded by postcss-load-config. Also I want to mention that typescript 4.5 has |
@ZerdoX-x it already should be supported https://github.com/postcss/postcss-load-config/blob/main/src/index.js#L91 |
Yes, adding Please, send PR. |
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> ### What? Prevent confusing error messages when changing to `"type": "module"` in `package.json` ``` ./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[2].oneOf[8].use[1]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[2].oneOf[8].use[2]!./src/styles/index.css Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/my/repo/components/postcss.config.js from /path/to/my/repo/components/node_modules/next/dist/lib/find-config.js not supported. Instead change the require of postcss.config.js in /path/to/my/repo/components/node_modules/next/dist/lib/find-config.js to a dynamic import() which is available in all CommonJS modules. ``` ### Why? Even though PostCSS itself [supports ESM and TypeScript configuration files](postcss/postcss-load-config#230), Next.js itself does not (because of `next/lib/find-config`): - #34448 ### How? By switching to `.cjs`, the config will stay recognized as CommonJS even after switching to `"type": "module"` in `package.json` cc @balazsorban44 --------- Co-authored-by: Sam Ko <[email protected]>
We need support
.postcssrc.mjs
orpostcss.config.mjs
.Also we need support
.postcssrc.cjs
orpostcss.config.cjs
.The text was updated successfully, but these errors were encountered: