-
Notifications
You must be signed in to change notification settings - Fork 808
bug: Building for Vite doesn't work even with enableImportInjection: true
#5637
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
Comments
UPDATE: I was able to get this to work in the minimum reproducible example by changing
Howver, I'm still unable to get building to work in the original example repo I'm doing this in here, despite installing the same version of the package above. It's throwing the same error on build: |
Hey @thebrandonlucas 👋 I'm not seeing a Stencil project in the minimal reproduction URL - https://github.com/thebrandonlucas/vite-build-test. Can you do me a favor and update that when you get a chance so that the team and I can take a closer look? Thanks! |
Thanks for the issue! This issue has been labeled as Please reproduce this issue in an Stencil starter component library and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed. If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue. For a guide on how to create a good reproduction, see our Contributing Guide. |
@rwaskiewicz My apologies, I was using a locally built package and must've removed it. The |
It looks like to get Vite working in this particular instance, you'll need to add a "exports": {
".": {
"import": "./dist/my-stencil/my-stencil.esm.js",
"require": "./dist/my-stencil/my-stencil.cjs.js"
},
"./my-component": {
"import": "./dist/components/my-component.js",
"types": "./dist/components/my-component.d.ts"
},
+ "./loader": {
+ "import": "./loader/index.cjs.js",
+ "types": "./loader/index.d.ts"
+ }
}, From there, rebuild your Stencil project, then publish/ I've closed this issue out, feel free to open a new one if this doesn't work as expected. |
Worked like a charm. Thanks for your help! |
this commit adds an export mapping to the loader package to `package.json`. prior to this commit, users working their way through stencil's guide for setting up the react output target would run into an error when trying to spin up a react app with vite: ``` vite v5.2.9 building for production... ✓ 7 modules transformed. x Build failed in 31ms error during build: Error: [commonjs--resolver] Missing "./loader" specifier in "stencil-library" package <STACK_TRACE_OMITTED> npm ERR! Lifecycle script `build` failed with error: npm ERR! Error: command failed npm ERR! in workspace: [email protected] npm ERR! at location: /private/tmp/react-set-asset-path/packages/my-app ``` this restores the behavior previously supported in #134, without requiring us to rewrite the react guide relates to: stenciljs/core#5637
Uh oh!
There was an error while loading. Please reload this page.
Prerequisites
Stencil Version
4.7.0
Current Behavior
Importing my web component in a Vite project (sveltekit, in this case) gives me the following error:
After searching around and seeing that Vite only works with ESM modules, I found a couple issues (#3961 and #4598) related that suggest setting
enableImportInjection: true
instencil.config.ts
. I set this, rebuilt and packed the stencil project, imported into my Vite project, and got the same error. Notably, it works fine in the dev build/server, just not production.Expected Behavior
The project should build with no errors and the element should render in both the production and dev servers.
System Info
`npx stencil info` System: node 20.11.1 Platform: darwin (22.5.0) CPU Model: Apple M1 Pro (8 cpus) Compiler: /Users/brandonlucas/src/lightning/bitcoin-qr/node_modules/@stencil/core/compiler/stencil.js Build: 1710782619 Stencil: 4.13.0 🚞 TypeScript: 5.4.2 Rollup: 2.56.3 Parse5: 7.1.2 jQuery: 4.0.0-pre Terser: 5.29.2
Steps to Reproduce
To reproduce:
enableImportInjection: true
.npm build
thennpm pack
the Stencil project, unpack withtar -xvf <package>
. Install it in the Vite project vianpm install --save <path-to-package>
defineCustomElements
into the app and call it:npm build
thennpm preview
to build & start the production server.I created a minimum reproducible Vite example here.
Code Reproduction URL
https://github.com/thebrandonlucas/bitcoin-qr/
Additional Information
No response
The text was updated successfully, but these errors were encountered: