tolgee / tolgee-js

Tolgee JavaScript libraries monorepo
https://tolgee.io
MIT License
219 stars 24 forks source link

Broken imports with Vue 3 and Histoire. #3244

Closed goulashify closed 9 months ago

goulashify commented 9 months ago

Hey there,

I ran into an issue using components w/ Tolgee inside Histoire stories:

Error while collecting story /Users/dani/dev/reacted/reacted-project/src-story/atom/form/Form.story.vue:
file:///Users/dani/dev/redacted/redacted-project/node_modules/@tolgee/vue/dist/tolgee-vue.esm.mjs:2
import { getFallback, getTranslateProps } from '@tolgee/web';
         ^^^^^^^^^^^
SyntaxError: Named export 'getFallback' not found. The requested module '@tolgee/web' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@tolgee/web';
const { getFallback, getTranslateProps } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async ViteNodeRunner.interopedImport (file:///Users/dani/dev/redacted/redacted-project/node_modules/vite-node/dist/client.mjs:324:28)
    at async ViteNodeRunner.directRequest (file:///Users/dani/dev/redacted/redacted-project/node_modules/vite-node/dist/client.mjs:224:24)
    at async ViteNodeRunner.cachedRequest (file:///Users/dani/dev/redacted/redacted-project/node_modules/vite-node/dist/client.mjs:156:14)
    at async ViteNodeRunner.dependencyRequest (file:///Users/dani/dev/redacted/redacted-project/node_modules/vite-node/dist/client.mjs:204:14)
    at async /Users/dani/dev/redacted/redacted-project/src-story/atom/form/Form.story.vue:8:31
    at async ViteNodeRunner.directRequest (file:///Users/dani/dev/redacted/redacted-project/node_modules/vite-node/dist/client.mjs:312:5)
    at async ViteNodeRunner.cachedRequest (file:///Users/dani/dev/reacted/reacted-project/node_modules/vite-node/dist/client.mjs:156:14)

To me it seems like the "scanning" process (running in Node) is failing to import Tolgee properly. Inside the browser it works great. Potentially related to some other issues @JanCizmar worked on recently (similar error).

Could someone take a look please?


I'm running latest versions from everything, see reproduced in Stackblitz: https://stackblitz.com/edit/vite-k7xmw2?file=src%2FApp.vue.

stepan662 commented 9 months ago

Thanks for reporting. I'll try to fix that.

goulashify commented 9 months ago

Super duper, thanks Štěpán!

goulashify commented 9 months ago

Just tested, works great, thanks again!