Skip to content

error TS2305: Module 'vue' has no exported member 'mergeDefaults' #440

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

Closed
zhong1998 opened this issue Feb 24, 2023 · 4 comments
Closed

error TS2305: Module 'vue' has no exported member 'mergeDefaults' #440

zhong1998 opened this issue Feb 24, 2023 · 4 comments
Labels
kind: support Asking for support with something or a specific use case problem: no repro No reproduction was provided (and have not tried to repro without one) scope: integration Related to an integration, not necessarily to core (but could influence core) scope: vue Related to integration with Vue (rollup-plugin-vue is long archived), not core solution: duplicate This issue or pull request already exists solution: out-of-scope This is out of scope for this project solution: Vue behavior This is Vue's behavior as well, so this is not a bug with this plugin

Comments

@zhong1998
Copy link

zhong1998 commented Feb 24, 2023

Troubleshooting

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior

  2. Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate

  3. Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction

What happens and why it is incorrect

I use export default definecomponent can be ok but use setup lang="ts" is false. it seems the plugin is wrong in run time.

Environment

<template>
  <img :src="src" class="component" :style="styleProps" @click.prevent="handleClick">
</template>

<script lang="ts" setup>
import {defineProps, withDefaults} from "vue"
import useComponentCommon from "./../../hook/useComponentCommon"
import {imageDefaultProps, imageStylePropsNames} from "../../defaultProps"

interface imgProps {
  src: string;
  actionType: string;
  url: string;
  // size
  height: string;
  width: string;
  paddingLeft: string;
  paddingRight: string;
  paddingTop: string;
  paddingBottom: string;
  // border type
  borderStyle: string;
  borderColor: string;
  borderWidth: string;
  borderRadius: string;
  // shadow and opacity
  boxShadow: string;
  opacity: string;
  // position and x,y
  position: string;
  left: string;
  top: string;
  right: string;
}

const props = withDefaults(defineProps<imgProps>(), {
  ...imageDefaultProps
})
const {styleProps, handleClick} = useComponentCommon(props, imageStylePropsNames)
</script>

<style scoped>
.component {
  max-width: 100%;
  position: relative !important;
}
</style>

Versions

"rollup-plugin-typescript2": "^0.34.1",


rollup.config.js

:
import fs from "fs"
import vue from "rollup-plugin-vue"
import css from "rollup-plugin-css-only"
import typescript from "rollup-plugin-typescript2";

const {name} = JSON.parse(fs.readFileSync("package.json", "utf-8"))
const file = type => `dist/${name}.${type}.js`

const overrides = {
    compilerOptions: {declaration: true},
}
export default {
    input: "src/index.ts",
    output: {
        name,
        file: file("esm"),
        format: 'es'
    },
    plugins: [
        typescript({tsconfigOverride:overrides}),
        vue(),
        css({output: "bundle.css"})
    ]
}

tsconfig.json

:
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "useDefineForClassFields": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "jest"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

package.json

:
{
  "name": "xxxx",
  "version": "xxxx",
  "private": true,
  "type": "module",
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit",
    "lint": "vue-cli-service lint",
    "build:esm": "rollup --config build/rollup.config.js"
  },
  "dependencies": {
    "core-js": "^3.8.3",
    "lodash-es": "^4.17.21",
    "vue": "^3.2.13"
  },
  "devDependencies": {
    "@types/jest": "^27.0.1",
    "@types/lodash-es": "^4.17.6",
    "@typescript-eslint/eslint-plugin": "^5.4.0",
    "@typescript-eslint/parser": "^5.4.0",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-plugin-typescript": "~5.0.0",
    "@vue/cli-plugin-unit-jest": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "@vue/eslint-config-typescript": "^9.1.0",
    "@vue/test-utils": "^2.0.0-0",
    "@vue/vue3-jest": "^27.0.0-alpha.1",
    "babel-jest": "^27.0.6",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "jest": "^27.0.5",
    "rollup-plugin-css-only": "^4.3.0",
    "rollup-plugin-typescript2": "^0.34.1",
    "rollup-plugin-vue": "^6.0.0",
    "ts-jest": "^27.0.4",
    "tslib": "^1.14.1",
    "typescript": "~4.5.5"
  }
}

plugin output with verbosity 3

:

@agilgur5 agilgur5 changed the title [!] (plugin rpt2) RollupError: src/components/LShape/LShape.vue?vue&type=script&setup=true&lang.ts:1:10 - error TS2305: Module '"vue"' has no exported member 'mergeDefau lts'. `error TS2305: Module 'vue' has no exported member 'mergeDefaults' Mar 13, 2023
@agilgur5 agilgur5 changed the title `error TS2305: Module 'vue' has no exported member 'mergeDefaults' error TS2305: Module 'vue' has no exported member 'mergeDefaults' Mar 13, 2023
@agilgur5 agilgur5 added scope: integration Related to an integration, not necessarily to core (but could influence core) solution: duplicate This issue or pull request already exists scope: vue Related to integration with Vue (rollup-plugin-vue is long archived), not core kind: support Asking for support with something or a specific use case solution: out-of-scope This is out of scope for this project problem: no repro No reproduction was provided (and have not tried to repro without one) solution: Vue behavior This is Vue's behavior as well, so this is not a bug with this plugin labels Mar 14, 2023
@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 14, 2023

So there was no repro provided here and no logs either, but this issue sounds very similar to #325 with the case of Vue SFCs (also potentially #235 / vuejs/rollup-plugin-vue#311). Per #325, that is due to a problem in Vue typings or rollup-plugin-vue (which has long been unmaintained), and so it is out of the control and scope of rpt2 (similarly, #235 is due to a bug in rollup-plugin-vue vuejs/rollup-plugin-vue#311)

That being said, there is a workaround provided in #325 that may work for your issue as well

@wwei-github
Copy link

Has this problem been solved? I have also encountered this, but I don't know why

@veco9
Copy link

veco9 commented Jun 1, 2023

I'm experiencing the same issue. The problem arises due to the destructuring that occurs in the "defaults" parameter of the "withDefaults" function.

{
  ...imageDefaultProps
}

Even if you pass it like this:

{
   ...{someProperty: "foo"}
}

or

{
   Object.assign({}, {someProperty: "foo"})
}

I have also left a comment on the issue vite-plugin-dts#188.
I would greatly appreciate any assistance or possible workarounds.

@agilgur5
Copy link
Collaborator

Per qmhc/vite-plugin-dts#188 (comment), it looks like this indeed was a Vue typings issue:

I've found a comment in [email protected] "runtime-core.d.ts":
/* removed internal: mergeDefaults */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case problem: no repro No reproduction was provided (and have not tried to repro without one) scope: integration Related to an integration, not necessarily to core (but could influence core) scope: vue Related to integration with Vue (rollup-plugin-vue is long archived), not core solution: duplicate This issue or pull request already exists solution: out-of-scope This is out of scope for this project solution: Vue behavior This is Vue's behavior as well, so this is not a bug with this plugin
Projects
None yet
Development

No branches or pull requests

4 participants