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

quasar.conf - support ESM or .cjs config files in module projects #9455

Closed
josh-hemphill opened this issue May 28, 2021 · 19 comments
Closed
Assignees

Comments

@josh-hemphill
Copy link

Is your feature request related to a problem? Please describe.
When people use module type projects, it results in confusing issues like #9454

Describe the solution you'd like
Ideally, it would support loading ESM config files, or maybe even TS

Describe alternatives you've considered
Converting project to classic type, or maybe manually playing around with ts-node or some kind of compilation?

Additional context
Add any other context or screenshots about the feature request here.

@IlCallo
Copy link
Member

IlCallo commented Jul 5, 2021

Here (#6476) there was a previous attempt to support ESM codebases, but I did it when ESM wasn't fully enabled into Node.
We could probably take another look at this in the future, now that we bumped the minimum Node version for @quasar/app to a version supporting ESM natively without flags

@therealcoder1337
Copy link

therealcoder1337 commented Nov 3, 2021

i would also love to see this ("type": "module" in package.json), since there are multiple benefits:

  • some coding style in vue code as in quasar config files
  • much easier testing, you can probably even drop babel (for testing) if you use esm modules
  • future proof / better support for modern packages, since commonjs (require) gets less and less used nowadays, compared to esm (import)

but i imagine it's a lot of work because you would have to rewrite the whole source code.

@hawkeye64
Copy link
Member

This will likely come with the Vite support that @rstoenescu is working on. When creating a new project, you will be asked if you want Webpack or Vite.

@IlCallo IlCallo linked a pull request Jan 14, 2022 that will close this issue
15 tasks
@IlCallo
Copy link
Member

IlCallo commented Feb 11, 2022

I'd also note that many upsteam projects are forcing the ecosystem by pushing Pure ESM packages

Due to this, it may be an idea to skip from Node 12 to Node 16 directly, we should check which are the main differences

@clintfoster
Copy link

clintfoster commented Aug 23, 2022

I'm wondering if any more thought has been given to this issue? I'm on Node 16 (LTS) and using Vite per https://quasar.dev/quasar-cli-vite/convert-to-quasar-cli-with-vite.

This has been working well for several weeks. I'm happy to be rid of Webpack, Babel, etc. It didn't occur to me to also switch to ESM module resolution until I recently added type: module to 2 other (non-Quasar) projects that I was able to get working with changes like the following:

  • Update eslint config to flag any "directory" imports.
  • Change all imports to explicitly specify filenames & extensions, e.g. index.js.
  • Deal with CommonJS config files, e.g. convert .eslintrc.js to .eslintrc.yml.
  • Update Jest, e.g. add useESM: true to jest.config.cjs.

I made the same changes to my Quasar project, and although lint is happy, I get the following error when I run quasar dev:

./node_modules/@quasar/app-vite/lib/quasar-config-file.js not supported.
quasar.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename quasar.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in ./package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at QuasarConfFile.read (./node_modules/@quasar/app-vite/lib/quasar-config-file.js:204:30)
    at goLive (./node_modules/@quasar/app-vite/lib/cmd/dev.js:142:43) {
  code: 'ERR_REQUIRE_ESM'

I tried changing the filename to quasar.config.cjs, with the following result (presumably because it isn't finding the configuration file):

Error Unknown command "dev"

@IlCallo
Copy link
Member

IlCallo commented Aug 24, 2022

Not yet, even Node 16 have many quirks around ESM support unluckily.
We'll fix this in Quasar v3 for sure, but we cannot assure we'll be able to squeeze it in Quasar v2 lifecycle and can't give any ETA about it

@clintfoster
Copy link

Thanks for the quick response. Probably it is naive of me to think a quick solution such as the dynamic loader explicitly looking for quasar.config.cjs (or supporting yaml format, as eslint does) would allow Quasar projects to use ESM module resolution. No doubt it is just a superficial symptom since the configuration file is the first thing that's loaded.

@jrgleason
Copy link

What is the timeline for Quasar 3? This is a big issue for us as we had to struggle with the same issues with tailwind so this was something we were looking to avoid in Quasar.

Thank you guys very much for all of your work.

@IlCallo
Copy link
Member

IlCallo commented Oct 20, 2022

@clintfoster there are many things to consider, eg a project using native ESM modules from Node (and we use Node in some parts of the framework) must import everything with fully specified path. The Node Loader API is still under heavy development by Node side and experimental

We may be able to make it work right now, but the vast majority of the ecosystem isn't ready yet, so it could bring many headaches with little benefit

I'll leave here some links I found around, since I bumped my head against this topic again today:

@IlCallo
Copy link
Member

IlCallo commented Oct 20, 2022

@jrgleason we planned to start working on it this quarter, but Vue 2.7 release could potentially result in a longer lifecycle for Qv1 and thus postponing Qv3 works, as we don't have enough bandwidth to maintain 3 major version of the framework at the same time

Right now we're spending our energies to enhance Qv2 as much as possible instead of planning for Qv3

@ZerdoX-x
Copy link
Contributor

I can't imagine quasar still forces to use commonjs

Can be fixed via #15756

@IlCallo
Copy link
Member

IlCallo commented Apr 26, 2023

Quasar CLI packages (both vite and webpack) are currently being rewritten in ESM
The rewrite will allow using quasar.config with ESM and TS too

@ZerdoX-x
Copy link
Contributor

That quick fix in PR above can allow usage of quasar in ESM project if you put config in cjs file. I hope it will be reviewed properly. IMO it's an important issue which can be easily fixed without waiting for quasar 3 or the whole project being rewritten.

@rstoenescu
Copy link
Member

Posting my comment from the PR:

This has already been worked on for next q/app major versions (which will also support everything in ESM format, including the quasar config file).

However, adding this to the current q/apps will be nice as well. BUT, I need to release the new global Quasar CLI first, otherwise commands through it will still fail to recognize the folder as being a Quasar project.

So you will need to be a little patient until I can release the new q/cli.

@rstoenescu rstoenescu self-assigned this Apr 27, 2023
rstoenescu added a commit that referenced this issue Apr 29, 2023
* feat: support quasar.conf(ig).cjs

#9455
I would like to use Quasar with `"type": "module"` in my `package.json`.

Without converting file to `cjs` I get an error from Node:
```
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/zerdox/p/cryp/table-cups/quasar.config.js from /Users/zerdox/p/cryp/table-cups/node_modules/@quasar/app-vite/lib/quasar-config-file.js not supported.
quasar.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename quasar.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/zerdox/p/cryp/table-cups/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at QuasarConfFile.read (/Users/zerdox/p/cryp/table-cups/node_modules/@quasar/app-vite/lib/quasar-config-file.js:204:30)
    at build (/Users/zerdox/p/cryp/table-cups/node_modules/@quasar/app-vite/lib/cmd/build.js:134:43) {
  code: 'ERR_REQUIRE_ESM'
}

 App • ⚠️   FAIL  quasar.config.js has JS errors
```

Please let me stick with ESM :)

* Update app-paths.js

---------

Co-authored-by: Razvan Stoenescu <razvan.stoenescu@gmail.com>
@tachibana-shin
Copy link

It looks like it will be quite a while until a release that supports quasar.config ESM/TS comes out. For those who can't wait this will be a temporary solution for them to be able to use quasar.config.ts (or .cjs, .mjs depending on need) until the release new release:
https://gist.github.com/tachibana-shin/284839d678a3c4be709188dc4b14b6df

@Tofandel
Copy link
Contributor

Tofandel commented Jan 31, 2024

Any news regarding the ESM/TS quasar config? I'm using vite 5 and the next major of vite will remove CJS support

When building this warning pops up
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

@IlCallo
Copy link
Member

IlCallo commented Feb 1, 2024

The next major version, currently in alpha phase as we finish the upgrade docs, natively supports ESM and TS

@MartinX3
Copy link

MartinX3 commented Mar 31, 2024

@yusufkandemir would it make sense to change the default module to a newer value (NodeNext) in

"module": "esnext",

Also we should set "verbatimModuleSyntax": true and with NodeNext we can remove

And according to https://www.typescriptlang.org/tsconfig#moduleResolution our used value node is also deprecated and got replaced by node10 in the official tsconfig to show that it's old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.