uni-helper / vite-plugin-uni-pages

为 Vite 下的 uni-app 提供基于文件系统的路由
https://uni-helper.js.org/vite-plugin-uni-pages
MIT License
114 stars 15 forks source link

Cannot use import statement outside a module #181

Closed weiminghaoo closed 1 month ago

weiminghaoo commented 2 months ago

描述问题

从0.2.25版本之后 报错 SyntaxError: Cannot use import statement outside a module

image

复现

mac node v18.19.0 vite-plugin-uni-pages 版本0.2.25之后的版本

系统信息

基础环境信息:

基础依赖信息:

使用的包管理器

pnpm

核对

ModyQyW commented 2 months ago

请提供复现仓库

iceDays commented 2 months ago

使用 vitesse-uni-app 模板,更新"@uni-helper/vite-plugin-uni-pages": "0.2.26" 后,会导致 node18 版本提示该错误以及 (node:55908) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

weiminghaoo commented 2 months ago

an ES module, set "type": "module" in the package.json or use the .mjs extension.

是的

wenf0 commented 2 months ago

an ES module, set "type": "module" in the package.json or use the .mjs extension.

是的

[HBuilder] 17:51:31.224 TypeError: self.findLastIndex is not a function [HBuilder] 17:51:31.232 at /Users/ananas/i/wave-m4-app/node_modules/.pnpm/@uni-helper+vite-plugin-uni-pages@0.2.26/node_modules/@uni-helper/vite-plugin-uni-pages/dist/index.cjs:475:35

打包app报错

Skiyee commented 2 months ago

朋友们,vitesse-uni-app 模板未能复现你们所描述的问题,请提供最小复现,否则该issue是无法推进的

dshuais commented 2 months ago

请问这个问题解决了吗?遇到了同样的问题

dshuais commented 2 months ago

请问这个问题解决了吗?遇到了同样的问题

但是减低版本到0.2.14解决了这个问题

Skiyee commented 2 months ago

最后一次提醒,我使用 vitesse-uni-app该插件升级至最新版本 未能复现此问题,需要有朋友提供最小复现

现在猜测可能是由某个外部依赖升级导致

dshuais commented 2 months ago

最后一次提醒,我使用 vitesse-uni-app该插件升级至最新版本 未能复现此问题,需要有朋友提供最小复现

现在猜测可能是由某个外部依赖升级导致

他们可能已经解决了,或没有功夫去生成最小复现。

我正在使用你们的产品搭建一个自己使用的模板,地址:https://github.com/dshuais/uni3-template

使用pages.config.ts的话 会持续报这个错误,但我已经通过修改文件名为pages.config.mjs解决了这个问题,具体还是不知道是哪个外部依赖导致,如果这个issue还被跟进的话可以麻烦您试试,或者可以关闭这个issue,因为大家可能都已经解决。

最后,你们的产品很棒!

wtto00 commented 2 months ago

使用 vitesse-uni-app 模板,更新"@uni-helper/vite-plugin-uni-pages": "0.2.26" 后,会导致 node18 版本提示该错误以及 (node:55908) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

image 我确实复现到了,做了几个测试 @uni-helper/vite-plugin-uni-pages node 结果
0.2.24 18
0.2.25 18
0.2.25 20
wtto00 commented 2 months ago

抽空看了下提交记录:https://github.com/uni-helper/vite-plugin-uni-pages/compare/v0.2.24...v0.2.25

然后研究测试后,发现是这里 unconfig 版本导致的问题:

-    "unconfig": "^0.3.13",
+    "unconfig": "^0.4.5",
nodejs v18 下经过测试 pnpm play:mp-weixin: unconfig 结果
0.3.13
0.4.0

应该是 unconfig v0.4.0 中的这个 Breaking Changes 改动 https://github.com/antfu-collective/unconfig/pull/28 导致报错 Cannot use import statement outside a module 的问题。

ModyQyW commented 1 month ago

Please try v0.2.27. And big thanks to @wtto00 ♥️

ModyQyW commented 1 month ago

如果没有进一步反馈,我会在本周内关闭这个问题,谢谢