当前位置:   article > 正文

报TypeError: Cannot read property ‘endsWith‘ of undefined_cannot read property 'endswith' of undefined

cannot read property 'endswith' of undefined

在cloen下载vue3项目,npm  i 完成后,npm run serve 报以下错误信息

  1. $ npm run serve
  2. > vben-admin@2.8.0 serve D:\gongfeng\tz-sale-web
  3. > npm run dev
  4. > vben-admin@2.8.0 dev D:\gongfeng\tz-sale-web
  5. > vite
  6. failed to load config from D:\gongfeng\tz-sale-web\vite.config.ts
  7. error when starting dev server:
  8. TypeError: Cannot read property 'endsWith' of undefined
  9. at configHtmlPlugin (D:\gongfeng\tz-sale-web\vite.config.ts:375:34)
  10. at createVitePlugins (D:\gongfeng\tz-sale-web\vite.config.ts:697:20)
  11. at vite_config_default (D:\gongfeng\tz-sale-web\vite.config.ts:781:14)
  12. at loadConfigFromFile (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\chunks\dep-689425f3.js:61937:15)
  13. at processTicksAndRejections (internal/process/task_queues.js:93:5)
  14. at async resolveConfig (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\chunks\dep-689425f3.js:61456:28)
  15. at async createServer (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\chunks\dep-689425f3.js:60111:20)
  16. at async CAC.<anonymous> (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\cli.js:688:24)
  17. npm ERR! code ELIFECYCLE
  18. npm ERR! errno 1
  19. npm ERR! vben-admin@2.8.0 dev: `vite`
  20. npm ERR! Exit status 1
  21. npm ERR!
  22. npm ERR! Failed at the vben-admin@2.8.0 dev script.
  23. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  24. npm ERR! A complete log of this run can be found in:
  25. npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2022-10-25T03_00_16_960Z-debug.log
  26. npm ERR! code ELIFECYCLE
  27. npm ERR! errno 1
  28. npm ERR! vben-admin@2.8.0 serve: `npm run dev`
  29. npm ERR! Exit status 1
  30. npm ERR!
  31. npm ERR! Failed at the vben-admin@2.8.0 serve script.
  32. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  33. npm ERR! A complete log of this run can be found in:
  34. npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2022-10-25T03_00_16_996Z-debug.log

重新npm i 依旧报错,最后想到使用yarn来安装试试。

  1. $ yarn
  2. yarn install v1.22.17
  3. info No lockfile found.
  4. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix
  5. package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
  6. [1/5] Validating package.json...
  7. [2/5] Resolving packages...
  8. warning conventional-changelog-cli > tempfile > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
  9. warning vite-plugin-imagemin > imagemin-gifsicle > gifsicle@5.3.0: [WARNING] Use 5.2.1 instead of 5.3.0, reason: https://github.com/imagemin/gifsicle-bin/issues/133
  10. warning vite-plugin-imagemin > imagemin-optipng > exec-buffer > tempfile > uuid@3.4.0: Please upgrade to version 7 or higher.
  11. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
  12. warning vite-plugin-imagemin > imagemin-svgo > svgo > stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
  13. warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
  14. warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
  15. warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
  16. warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
  17. warning vue-tsc > vscode-vue-languageservice@0.29.8: WARNING: This project has been renamed to @volar/vue-language-service. Install using @volar/vue-language-service instead.
  18. warning vue-tsc > vscode-vue-languageservice > @volar/html2pug@0.29.8: WARNING: This project has been renamed to @johnsoncodehk/html2pug. Install using @johnsoncodehk/html2pug instead.
  19. warning vue-tsc > vscode-vue-languageservice > vscode-pug-languageservice@0.29.8: WARNING: This project has been renamed to @volar/pug-language-service. Install using @volar/pug-language-service instead.
  20. warning vue-tsc > vscode-vue-languageservice > vscode-typescript-languageservice@0.29.8: WARNING: This project has been renamed to @volar/typescript-language-service. Install using @volar/typescript-language-service instead.
  21. [3/5] Fetching packages...
  22. error @typescript-eslint/eslint-plugin@5.41.0: The engine "node" is incompatible with this module. Expected version "^12.22.0 || ^14.17.0 || >=16.0.0". Got "14.16.1"
  23. error Found incompatible module.
  24. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

还是报错,但是这次的报错就很明确了,node版本不对,必须大于16.0.0

 切换nvm的node版本。从14.16.1改为116.13.2

重新yarn,没有报错

 

 yarn serve依旧报错

 百度了一下发现endsWidth是js的写法,我就搜有没有例外的写法,果然黄天不负苦心人,搜到了  'abcdef'.split("f").slice(-1)[0] === ""   这种判断方法

  1. "被查询字符串".split("结尾字符串").slice(-1)[0] === ""
  2. 例如:
  3. 'abcdef'.split("g").slice(-1)[0] === "";//false
  4. 'abcdef'.split("abcde").slice(-1)[0] === "";//false
  5. 'abcdef'.split("f").slice(-1)[0] === "";//true
  6. 'abcdef'.split("def").slice(-1)[0] === "";//true
  7. 例如判断格式exe
  8. "文.件.名.exe".split('.').slice(-1)[0] === "exe"//true
  9. "文.exe.件.名".split('.').slice(-1)[0] === "exe"//false
  10. "文.件.名exe.".split('.').slice(-1)[0] === "exe"//false
  11. "文件名.exe.abc.exe.abc".split('.').slice(-1)[0] === "exe"//false

但是还在报错,我就猜测不是方法的问题,是前面值的问题,增加了一个 '?'  就不报错了。

 

欧克了,兄弟们,曲折啊,前进的道路上几多崎岖啊。

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/691718
推荐阅读
相关标签
  

闽ICP备14008679号