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

Unable to use with Vite in non-ember projects #2022

Closed
sukima opened this issue Sep 16, 2023 · 12 comments
Closed

Unable to use with Vite in non-ember projects #2022

sukima opened this issue Sep 16, 2023 · 12 comments

Comments

@sukima
Copy link

sukima commented Sep 16, 2023

I discovered a bug when following the instructions to install qunit-dom. I seems to expect Vite to include Broccollii with the bundled for browser output. I think this might have to do with the package.json not providing a main and the default index.js is an ember-cli addon module.

The basic premise was I had qunit working and I added qunit-dom like this:

  1. Add qunit-dom to package.json devDependencies
  2. Add import ‘qunit-dom’; to my test start up module (after first import of qunit)
  3. Run vite (dev server)
  4. Load page in browser

The console produces the following error:

Uncaught ReferenceError: process is not defined
    at node_modules/quick-temp/node_modules/rimraf/rimraf.js (rimraf.js:23)
    at __require2 (chunk-OROXOI2D.js?v=1ddafd9e:16)
    at node_modules/quick-temp/index.js (index.js:4)
    at __require2 (chunk-OROXOI2D.js?v=1ddafd9e:16)
    at node_modules/broccoli-plugin/dist/read_compat.js (read_compat.ts:4)
    at __require2 (chunk-OROXOI2D.js?v=1ddafd9e:16)
    at node_modules/broccoli-plugin/dist/index.js (index.ts:11)
    at __require2 (chunk-OROXOI2D.js?v=1ddafd9e:16)
    at node_modules/broccoli-funnel/index.js (index.js:6)
    at __require2 (chunk-OROXOI2D.js?v=1ddafd9e:16)

Steps to reproduce

  1. Clone https://github.com/sukima/lit-app-starter-kit
  2. Install packages bun i, npm i, pnpm i your preference I chose Bun
  3. run the dev script bun run dev
  4. Open in browser http://localhost:3000/tests/

This is the problematic commit: sukima/lit-app-starter-kit@42220f7

You can verify it is qunit-dom by git checkout HEAD^ and running the steps above.

@NullVoxPopuli
Copy link
Contributor

I think defining an exports key should also help resolve, which we'd probably want to align with modern package.jsons (provided it includes default and types)

Additionally, we can specify for v1 addons to not use index.js via specifying ember-addon-main in ember-addon

@NullVoxPopuli
Copy link
Contributor

Ah, here is how: https://github.com/embroider-build/embroider/blob/17cf74c90573a22648807786d20360a5715ae038/packages/macros/package.json#L67

@sukima
Copy link
Author

sukima commented Sep 16, 2023

Yes, this I think is what prevents me from incorporating qunit-dom into every project I touch.

NullVoxPopuli added a commit to NullVoxPopuli/qunit-dom that referenced this issue Sep 23, 2023
NullVoxPopuli added a commit to NullVoxPopuli/qunit-dom that referenced this issue Sep 23, 2023
NullVoxPopuli added a commit to NullVoxPopuli/qunit-dom that referenced this issue Sep 27, 2023
NullVoxPopuli added a commit to NullVoxPopuli/qunit-dom that referenced this issue Oct 6, 2023
NullVoxPopuli added a commit to NullVoxPopuli/qunit-dom that referenced this issue Oct 6, 2023
Remove old files and dependencies from qunit-dom

Add new test index.html that demonstrates the problem in mainmatter#2022

Fix exports

Ah, so we do compile to ESM already

We have to remove the ember-addon keyword because we don't want to provide an addon-main and then have a dependency on @embroider/addon-shim
NullVoxPopuli added a commit to NullVoxPopuli/qunit-dom that referenced this issue Oct 6, 2023
Remove old files and dependencies from qunit-dom

Add new test index.html that demonstrates the problem in mainmatter#2022

Fix exports

Ah, so we do compile to ESM already

We have to remove the ember-addon keyword because we don't want to provide an addon-main and then have a dependency on @embroider/addon-shim
@NullVoxPopuli
Copy link
Contributor

#2028 is now merged, so we're only waiting for release now

@NullVoxPopuli
Copy link
Contributor

@sukima v 3.0.0-rc.1 should be installable and compatible with Vite 💪

@sukima
Copy link
Author

sukima commented Oct 7, 2023

Wowzers!

pnpm add qunit-dom@3.0.0-rc.2
Packages: +1 -294
+------------------------------------------------------------------------------------------------------------------------------------------
Progress: resolved 61, reused 39, downloaded 1, added 1, done

dependencies:
- qunit-dom 2.0.0
+ qunit-dom 3.0.0-rc.2

Done in 3.8s

@sukima
Copy link
Author

sukima commented Oct 7, 2023

Confirmed, it works

IMG_0176

@NullVoxPopuli
Copy link
Contributor

I'm now using the rc.2 release on https://limber.glimdown.com and https://tutorial.glimdown.com https://github.com/NullVoxPopuli/limber/blob/main/apps/repl/package.json#L123

🎉

To get the types resolved, I did need to change my tsconfig to extend from @tsconfig/ember, which, in reality needed:

"moduleResolution": "bundler",

So, I think for qunit-dom sanity, I'm going to PR some test projects that focus on the bare minimum to prove this stays working over time.

@sukima
Copy link
Author

sukima commented Oct 8, 2023

Ran into an issue where the tsserver was unable to see the qunit-dom module. Do you have any advise @NullVoxPopuli ?

https://github.com/sukima/lit-app-starter-kit/tree/qunit-dom

@sukima
Copy link
Author

sukima commented Oct 8, 2023

qunit-dom is still very var GLOBAL. I’m curious why it feels the need for that now that modules are kind of the default for everything these days. Especially with UMD being several years in common use. Is that why things are so difficult?

@NullVoxPopuli
Copy link
Contributor

Do you have moduleResolution set to bundler?

I'm about to make some types test packages that show minimum required ts config

@NullVoxPopuli
Copy link
Contributor

After this is merged and released: #2065

compatibility with varying projects should be a bit more broad.

@sukima sukima closed this as completed Mar 27, 2024
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

No branches or pull requests

2 participants