[v9.0.0-rc.1] "The `@nextcloud/vue` library was used without setting / replacing the `appName`"
Since 9.0.0-alpha.8 (and still with v9.0.0-rc.1) my app shows an error in the browser console:
chunk-MD7AZ4D5.js?v=b43cf7f5:91 [ERROR] @nextcloud/vue: The `@nextcloud/vue` library was used without setting / replacing the `appName`. {uid: 'johndoe', app: '@nextcloud/vue', level: 0}
log @ chunk-MD7AZ4D5.js?v=b43cf7f5:91
error @ chunk-MD7AZ4D5.js?v=b43cf7f5:109
(anonymous) @ appName.ts:15
I traced the cause down to src/utils/appName.ts:
try {
// @ts-expect-error This is a name replaces by the compiler
realAppName = appName
} catch {
logger.error('The `@nextcloud/vue` library was used without setting / replacing the `appName`.')
}
I don't understand what causes the exception. appName is defined and set to my application's name (tested within the entry script).
Possibly relevant because a "compiler" is involved: My app is built with vite and @nextcloud/vite-config.
Hi @hschletz,
Possibly relevant because a "compiler" is involved: My app is built with vite and @nextcloud/vite-config.
Actually, appName is supposed to be defined by "compiler" (bundler).
@nextcloud/vite-config sets the name either from its options (appName), or from env.npm_package_version which is package.json/name. Do you have it set in the options or in the package.json?
tested within the entry script
Could you show how you tested it?
Does it happen in both dev and prod build?
The app name is defined in appInfo/info.xml, which takes precedence over package.json. If I change the app name there, appName is set to that name. I also tested overriding the vame via the appName option in vite config, with the expected result.
In either case, the error still shows.
For testing, I inserted console.log(appName) in the entry script (the script passed to createAppConfig()), and additionally in the root Vue component. Both statements output the configured app name.
@hschletz do you have some custom config? For example the firstrunwizard also uses vite and v9 of nextcloud-vue, for that app we know it works: https://github.com/nextcloud/firstrunwizard/blob/master/vite.config.js
Yes, there is some custom configuration, but I don't see anything in there that might be relevant for this issue.
However, I noticed that the error only occurs with vite dev. When building my app with vite build, appName is defined when the code in appName.ts is invoked.
This might be a bug in @nextcloud/vite-config, but it's weird that appName is available in my own application code, but not in the library code.
Unlike application code, dependencies have prebundling in dev mode in Vite
Unlike application code, dependencies have prebundling in dev mode in Vite
Should make no difference as the appName should be set as global variable in dev mode so it should be available in all code parts (?). (In production build its replaced instead).