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

Antdv: Error introducing ant-design-vue in vite-ssg run build SyntaxError: Cannot use import statement outside a module #202

Closed
reaink opened this issue Sep 4, 2021 · 6 comments

Comments

@reaink
Copy link

reaink commented Sep 4, 2021

Steps:

  1. init vitesse, add ant-design-vuenpm add ant-design-vue@next
  2. use ant-design-vue component examplea-button in App.vue
  3. add vite.config.ts
import Components from 'unplugin-vue-components/vite'
    ...
    // https://github.com/antfu/unplugin-vue-components
    Components({
      extensions: ['vue', 'md'],
      dts: true,
      include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
      resolvers: [
        ...
        AntDesignVueResolver(),    insert line
      ],
    }),
   ...
  1. run script npm run build

Err:

node_modules/ant-design-vue/es/index.js:1
(function (exports, require, module, __filename, __dirname) { import * as components from './components';
                                                              ^^^^^^
SyntaxError: Cannot use import statement outside a module
@reaink reaink changed the title Error introducing ant-design-vue in vite-ssg SyntaxError: Cannot use import statement outside a module Error introducing ant-design-vue in vite-ssg run build SyntaxError: Cannot use import statement outside a module Sep 6, 2021
@ZainChen
Copy link

ZainChen commented Nov 5, 2021

I also encountered this problem.

@hannoeru hannoeru transferred this issue from antfu-collective/vite-ssg Nov 5, 2021
@yinjiazeng
Copy link

@ZainChen

Components({
  dts: true,
  resolvers: [
    (name) => {
      if (name.match(/^A[A-Z]/)) {
        const importName = name.slice(1);
        const path = resolve(__dirname, '.', 'node_modules/ant-design-vue/es').replace(
          /\\/g,
          '/',
        );
        return {
          importName,
          path,
          sideEffects: `${path}/${importName.toLowerCase()}/style`,
        };
      }
    },
  ],
})

@antfu antfu changed the title Error introducing ant-design-vue in vite-ssg run build SyntaxError: Cannot use import statement outside a module Antdv: Error introducing ant-design-vue in vite-ssg run build SyntaxError: Cannot use import statement outside a module Dec 2, 2021
@nabaonan
Copy link
Collaborator

nabaonan commented Dec 4, 2021

i find use cjs build is ok,change the dir from 'es' to 'lib'
pr #231
i add a option called cjs when you build ,set it true

 AntDesignVueResolver({
          cjs: process.env.NODE_ENV === 'production',
       
        }),

@antfu antfu closed this as completed in 6e8c4d1 Dec 5, 2021
@yejinjian
Copy link

@nabaonan I fix my problem with your suggest, but meet new question

xxxxx\node_modules\ant-design-vue\lib\style\default.css:5
[class^=ant-]::-ms-clear,
      ^^

SyntaxError: Unexpected token '^='
    at compileFunction (<anonymous>)

do you still use antdv with vite-ssg?

1 similar comment
@yejinjian
Copy link

@nabaonan I fix my problem with your suggest, but meet new question

xxxxx\node_modules\ant-design-vue\lib\style\default.css:5
[class^=ant-]::-ms-clear,
      ^^

SyntaxError: Unexpected token '^='
    at compileFunction (<anonymous>)

do you still use antdv with vite-ssg?

ascott18 pushed a commit to ascott18/unplugin-vue-components that referenced this issue Mar 4, 2023
Co-authored-by: Kellyton <kellyton@dingtalk.com>
@u007
Copy link

u007 commented Jul 30, 2024

same issue with @yejinjian , did you manage to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants