-
Notifications
You must be signed in to change notification settings - Fork 77
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
auto-define.js issue prevents Calcite Components React from loading #7575
Comments
CodeSandbox can sometimes takes a few days to catch up to the Or if its easier to setup a use case, here's the sample with @arjanvanzutphen WRT the above, could you add a sample with either the template upgraded to latest, or with the above link? |
Looks like the |
Maybe we can add some additional checks on the |
This also surfaced with the Maps SDK for JS team during initialization cc: @andygup. |
Thanks @geospatialem, I was able to repro using:
|
Here's a repro app: https://devtopia.esri.com/andy4683/arcgis-calcite-vite-react. It should be using the latest version of all the deps. Steps:
|
Updated the issue with a repro sample with CCR version 1.6.0 |
Apparently vite requires a plugin to handle dynamic imports the way webpack does: Using the dynamic import plugin with the following vite config resolved the issue for me: import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import dynamicImport from "vite-plugin-dynamic-import";
import { resolve } from "path";
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
"@esri/calcite-components": resolve(
"node_modules",
"@esri",
"calcite-components",
),
},
},
plugins: [
react(),
dynamicImport({
filter(id) {
return id.includes("/node_modules/@esri/calcite-components");
},
}),
],
}); Let me know if that doesn't work for anyone. For reference, we needed to use a dynamic import to make sure web components aren't defined on the server when using SSR frameworks. I'll switch our CRA example that I use for testing to a Vite one since that's the industry standard nowadays. |
Is there a way to do this without requiring a plugin, maybe by optionally disabling auto-import? This is not an official Vite plugin and it does not have a license file. I also worry that the auto-import is kind of magical, and could lead to hard-to-diagnose bugs (eg with hot reloading, lazy loading, test runners...) or broken environments with other bundlers (Parcel...) It also looks like tree shaking is not supported with the React output target, which may mean auto-import will import all react wrappers and all stencil components, which is why we are seeing errors from unused modules. Currently, I think we can control which stencil components are imported to manage bundle size To me the auto-import feature feels like a major change with some unknowns, and it may be worth making it opt-in to see the impact on different apps first, and maybe delaying a full re-release until a major / breaking calcite version |
…dbox (#7632) **Related Issue:** #7575 ## Summary CodeSandbox exposes `process`, which makes it look like NodeJS. The only way to determine it should be treated as the browser is the non-standard value they use for `process.platform`. ref: https://nodejs.org/api/process.html#processplatform
I'll see if I can solve this in the vite config without using that plugin.
When I was testing with your repro sample I only saw errors for all components in the dev server. When building and serving there was only one error for the component being used in the app.
I can look into making it opt in, but it would be adding even more magic because we are already patching Stencil's build to get it to work as is. The auto import already went out in 1.5.0 so unfortunately we can't delay it, and removing it would be a breaking change. |
This impacts ArcGIS Instant Apps |
@benelan Got it to work |
…7671) **Related Issue:** #7575 ## Summary Vite uses [`@rollup/plugin-dynamic-import-vars`](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars) for resolving dynamic imports that use an expression for the path, rather than a fixed string. The rollup plugin has a [limitation](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#imports-must-start-with--or-) that requires dynamic imports with expressions to use relative paths. > All imports must start relative to the importing file. The import should not start with a variable, an absolute path or a bare import Changing the module path to a fixed string in the patch script resolves the errors. It also ensures that only the components being used in the app are bundled.
Installed and assigned for verification. |
You should no longer need the vite plugin after updating to the v1.8.0 release that went out a few hours ago! |
Verified with |
Updated CCR to |
Verified with JS SDK |
Great to hear, thank you both @arjanvanzutphen and @andygup! 🎉 |
Working for us too -- for Vite dev server, Vite production builds, and Vitest -- thank you!! |
Tested and verified for Instant Apps, thanks! |
Check existing issues
Actual Behavior
Many, if not all, components don't load due to an auto-define.js error log.
I noticed that also components are mentioned in the error logs that I don't use in my application
Expected Behavior
The application loads as expected
Reproduction Sample
https://github.com/arjanvanzutphen/ccr-auto-define-issue
Reproduction Steps
npm install
npm run dev
Reproduction Version
1.6.0. in sample
Relevant Info
1.6.1 shows the same behavior and is not showing the components as they should
Regression?
1.5.1
Priority impact
p3 - want for upcoming milestone
Impact
The app doesn't get loaded. Version 1.6.0 is in this way unusable
Calcite package
Esri team
Professional Services - Services Delivery
The text was updated successfully, but these errors were encountered: