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

Error resolving buefy components.d.ts file #24

Open
7 tasks done
asmaloney opened this issue May 10, 2022 · 11 comments
Open
7 tasks done

Error resolving buefy components.d.ts file #24

asmaloney opened this issue May 10, 2022 · 11 comments
Labels
p2-has-workaround 🍰 Bug, but has workaround (priority)

Comments

@asmaloney
Copy link

Describe the bug

(See discussion.)

Short version:

When I try to import { BModalComponent } from 'buefy/types/components' in a vue2 project, vite will fail to run:

  vite v2.9.8 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 273ms.

The following dependencies are imported but could not be resolved:

  buefy/types/components (imported by [...]/vite-resolve-bug/src/components/HelloWorld.vue?id=0)

Are they installed?

Reproduction

https:/asmaloney/vite-resolve-bug

System Info

System:
    OS: macOS Mojave 10.14.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 1.71 GB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 18.0.0 - ~/dev/bin/node
    Yarn: 1.22.15 - ~/dev/bin/yarn
    npm: 8.9.0 - ~/dev/bin/npm
  Browsers:
    Brave Browser: 101.1.38.111
  npmPackages:
    vite: ^2.9.8 => 2.9.8

Used Package Manager

npm

Logs

> [email protected] dev
> vite --force --debug

  vite:config bundled config file loaded in 182.85ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:optimized-deps',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite-plugin-vue2',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:client-inject',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     force: true,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   esbuild: { include: /\.ts$/, exclude: /\.(tsx|jsx)$/ },
  vite:config   configFile: '[...]/src/vite-resolve-bug/vite.config.ts',
  vite:config   configFileDependencies: [
  vite:config     '[...]/src/vite-resolve-bug/vite.config.ts'
  vite:config   ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     server: { force: true }
  vite:config   },
  vite:config   root: '[...]/src/vite-resolve-bug',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '[...]/src/vite-resolve-bug/public',
  vite:config   cacheDir: '[...]/src/vite-resolve-bug/node_modules/.vite',
  vite:config   command: 'serve',
  vite:config   mode: 'development',
  vite:config   isWorker: false,
  vite:config   isProduction: false,
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) {},
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   },
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object]
  vite:config     ],
  vite:config     rollupOptions: {}
  vite:config   }
  vite:config } +6ms
Forced re-optimization of dependencies

  vite v2.9.8 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 284ms.

  vite:deps scanning for dependencies... { timestamp: true } +0ms
  vite:deps Crawling dependencies using entries:
  vite:deps   [...]/src/vite-resolve-bug/index.html +0ms
  vite:resolve 0.36ms /src/main.ts -> [...]/src/vite-resolve-bug/src/main.ts +0ms
  vite:resolve 2.00ms vue -> [...]/src/vite-resolve-bug/node_modules/vue/dist/vue.runtime.esm.js +4ms
  vite:resolve 1.14ms buefy -> [...]/src/vite-resolve-bug/node_modules/buefy/dist/esm/index.js +2ms
  vite:resolve 0.17ms ./App.vue -> [...]/src/vite-resolve-bug/src/App.vue +0ms
  vite:resolve 0.15ms ./components/HelloWorld.vue -> [...]/src/vite-resolve-bug/src/components/HelloWorld.vue +3ms
  vite:resolve 1.99ms buefy/types/components -> null +3ms
  vite:deps Scan completed in 34.92ms: {
  vue: '[...]/src/vite-resolve-bug/node_modules/vue/dist/vue.runtime.esm.js',
  buefy: '[...]/src/vite-resolve-bug/node_modules/buefy/dist/esm/index.js'
} +18ms
The following dependencies are imported but could not be resolved:

  buefy/types/components (imported by [...]/src/vite-resolve-bug/src/components/HelloWorld.vue?id=0)

Are they installed?

Validations

@asmaloney
Copy link
Author

If I copy the parts I need to a local file (src/common/buefy.d.ts) and import that instead:

import { BModalComponent } from '@/common/buefy'

...it runs fine. (Not a great workaround though.)

Anyone have any ideas why vite can't resolve this file properly in the minimal repro project?

@sapphi-red sapphi-red added p2-has-workaround 🍰 Bug, but has workaround (priority) pending triage and removed pending triage p2-has-workaround 🍰 Bug, but has workaround (priority) labels May 28, 2022
@sapphi-red
Copy link
Member

You can use import type { BModalComponent } from 'buefy/types/components' to workaround the error.

@sapphi-red
Copy link
Member

sapphi-red commented May 28, 2022

@sapphi-red sapphi-red added p2-has-workaround 🍰 Bug, but has workaround (priority) and removed pending triage labels May 28, 2022
@sapphi-red
Copy link
Member

related: vitejs/vite#4810

@asmaloney
Copy link
Author

You can use import type { BModalComponent } from 'buefy/types/components' to workaround the error.

Thanks @sapphi-red! That works.

Much better than having to duplicate a bunch of code.

@guilbep
Copy link

guilbep commented Nov 29, 2022

it also happens with echarts with 'echarts/types/dist/shared.d.ts' Thanks @sapphi-red ! It works! It's in the doc: https://vitejs.dev/guide/features.html#typescript
So I guess it's a non issue and it should be closed.

@asmaloney
Copy link
Author

So I guess it's a non issue and it should be closed.

Just because they documented it doesn't mean it's not a bug. 😄

That's just a workaround "to avoid potential problems like type-only imports being incorrectly bundled" (i.e. a bug).

@guilbep
Copy link

guilbep commented Nov 29, 2022

@asmaloney okay so, I I understand you correctly the problem is with typescript ? https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export ?

@asmaloney
Copy link
Author

I have no idea where the bug is - I just reported it.

@sapphi-red
Copy link
Member

sapphi-red commented Nov 29, 2022

Yeah, you should use type only imports where it's possible. But there's some libraries that imports type def files in the component.

#24 (comment)
You can see import Decimal from 'vue-slider-component/typings/utils/decimal'; doesn't throw an error if it existed in .ts.
So I think there could be a way to fix this. It might be impossible though.

@sapphi-red
Copy link
Member

related PR: vitejs/vite#5850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-has-workaround 🍰 Bug, but has workaround (priority)
Projects
None yet
Development

No branches or pull requests

3 participants