Vue 不能使用 <script import>?
2022-10-07
417
我用 VueJS 制作了一个网站,但是它不起作用。顶部的 App.vue 有
<script setup>
import Page from './components/Page.vue';
import Top from './components/Top.vue';
</script>
当我尝试运行开发模式:
vite dev (npm run dev)
或尝试构建它:
vite (npm run build)
它不像
</script>
处的最后一个
>
注意:我使用的是 JS 而不是 TS
它 不会 编译甚至运行开发服务器。
错误:
Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
11:07:43 am [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
Plugin: vite:import-analysis
File: D:/Developing/denhamrocknet/home/denhamrockjs/src/App.vue
1 | <script setup>
2 | import Page from '.Page.vue';
3 | import Top from '.Top.vue';
4 | </script>
| ^
5 |
6 |
at formatError (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40862:46)
at TransformContext.error (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40858:19)
at TransformContext.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37530:22)
at async Object.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:41111:30)
at async loadAndTransform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37373:29)
Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
11:08:30 am [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
Plugin: vite:import-analysis
File: D:/Developing/denhamrocknet/home/denhamrockjs/src/App.vue
1 | <script setup>
2 | import Top from './components/Top.vue';
3 | import Page from './components/Page.vue';
4 | </script>
| ^
5 |
6 |
at formatError (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40862:46)
at TransformContext.error (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40858:19)
at TransformContext.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37530:22)
at async Object.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:41111:30)
at async loadAndTransform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37373:29)
结束
我不知道为什么。我发现设置:
module.exports = { publicPath: ''
否则它只是一个空白页,尽管当我这样做时我会收到此错误
和
一个白页。
PS:一切都有帮助!我会尝试一切。我迫切希望它能起作用。
已修复问题!
1个回答
我找到了解决办法!
我刚刚从配置中删除了:
module.exports = { publicPath: '' >
,现在一切正常!我肯定犯了一个错误,添加了代码,修复了错误,现在删除了错误代码。
希望这对遇到同样问题的人有所帮助!
Denhamrock
2022-10-07