报TypeError: Cannot read property ‘endsWith‘ of undefined

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

$ npm run serve

> vben-admin@2.8.0 serve D:\gongfeng\tz-sale-web
> npm run dev


> vben-admin@2.8.0 dev D:\gongfeng\tz-sale-web
> vite

failed to load config from D:\gongfeng\tz-sale-web\vite.config.ts
error when starting dev server:
TypeError: Cannot read property 'endsWith' of undefined
    at configHtmlPlugin (D:\gongfeng\tz-sale-web\vite.config.ts:375:34)
    at createVitePlugins (D:\gongfeng\tz-sale-web\vite.config.ts:697:20)
    at vite_config_default (D:\gongfeng\tz-sale-web\vite.config.ts:781:14)
    at loadConfigFromFile (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\chunks\dep-689425f3.js:61937:15)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async resolveConfig (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\chunks\dep-689425f3.js:61456:28)
    at async createServer (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\chunks\dep-689425f3.js:60111:20)
    at async CAC.<anonymous> (D:\gongfeng\tz-sale-web\node_modules\vite\dist\node\cli.js:688:24)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vben-admin@2.8.0 dev: `vite`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vben-admin@2.8.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2022-10-25T03_00_16_960Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vben-admin@2.8.0 serve: `npm run dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vben-admin@2.8.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2022-10-25T03_00_16_996Z-debug.log

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

$ yarn
yarn install v1.22.17
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix 
package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/5] Validating package.json...
[2/5] Resolving packages...
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.       
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
warning vite-plugin-imagemin > imagemin-optipng > exec-buffer > 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.
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
warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
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
warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
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.
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.
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.
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.
[3/5] Fetching packages...
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"
error Found incompatible module.
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] === ""   这种判断方法

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

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

 

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

 

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
TypeError: Cannot read property 'call' of undefined错误是指在调用一个未定义的对象的call方法时发生的错误。根据引用和引用[2]的内容,我们可以了解到这个错误通常发生在使用Vue.js路由时,可能是因为路由配置有误导致调用了未定义的函数或方法。 根据引用中提到的错误详情,TypeError通常是由于变量或参数不是预期类型引起的。在Vue.js中,路由配置常常使用到call方法来调用相应的函数,而当调用的对象是undefined时,就会触发该错误。 举个例子,假设在Vue.js路由配置中有如下代码: ```javascript router.beforeEach((to, from, next) => { // 在此处调用了一个不存在的函数 to.meta.beforeEnter.call(); next(); }); ``` 在这个例子中,to.meta.beforeEnter是一个函数对象,但如果这个函数对象未定义,就会产生TypeError: Cannot read property 'call' of undefined错误。 因此,解决这个错误的方法就是确保在路由配置中所调用的函数或方法都是已定义的。可以检查路由配置文件,确保所有使用到call方法的函数都是存在的。另外,也可以在调用函数之前先进行类型判断,避免调用未定义的函数。 总结起来,TypeError: Cannot read property 'call' of undefined错误通常发生在Vue.js路由配置中,是由于调用了未定义的函数或方法导致的。解决这个错误的方法是确保所有调用的函数都是已定义的,并进行必要的类型判断。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

arguments_zd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值