Search code examples
javascriptvue.jsrollup

Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) rollup vue package


I wanna try to rollup a vue component library. But I got the error on my type checking. I try to update typescript as here has been mentioned but it didn't work. here is my code and package.json My component code which has been exported as a Button

 <template>
  button
    >{{ children }}</button>
</template>

<script lang="tsx">

declare type IconMode =
  | {
      iconMode?: "without-icon";
    }
  | {
      iconMode: "with-icon" | "icon-only";
      iconName: string;
    };
 ...
 </script>

and rollup.config.js is:

import commonjs from "@rollup/plugin-commonjs"; 
import vue from "rollup-plugin-vue"; 
import buble from "@rollup/plugin-buble"; 
import typescript from "@rollup/plugin-typescript";


export default {
  input: "src/index.ts",
  output: {
    name: "Button",
    exports: "named"
  },
  plugins: [
    typescript(),
    vue({
      css: true, 
      compileTemplate: true 
    }),
    commonjs()
  ]
};

But I got this error on the terminal:

[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/Components/Button.vue?vue&type=script&lang.tsx (18:8)

18  declare type IconMode =
            ^ 
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

I'll be thankful if you could help me.


Solution

  • the problem is with the @rollup/plugin-typescript uninstall @rollup/plugin-typescript and install rollup-plugin-typescript2 instead.