element-plus / element-plus-nuxt-starter

🌰 A starter example for element-plus with Nuxt 3.
https://element-plus-nuxt.vercel.app
MIT License
297 stars 82 forks source link

I run error when import { ElMessage } from "element-plus"; #6

Closed mlsjla closed 3 years ago

mlsjla commented 3 years ago

run error


<script>
import { ElMessage } from "element-plus";
</script>

success

<script>
// import { ElMessage } from "element-plus";
</script>

error tips

Cannot use import statement outside a module

at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at ModuleWrap. (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:2358:3)
YunYouJun commented 3 years ago

Yeah, because Nuxt does service-side rendering, you can use it by importing the commonjs version element-plus/lib.

Refer the updated example.

Incidentally, I believe that with the nuxt update, there should be a better solution, for the time being, put up with it.