报TypeError: Cannot read property ‘endsWith‘ of undefined

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

$ npm run serve

> [email protected] serve D:\gongfeng\tz-sale-web
> npm run dev


> [email protected] 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! [email protected] dev: `vite`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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! [email protected] serve: `npm run dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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 > [email protected]: 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 > [email protected]: [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 > [email protected]: 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 > [email protected]: 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 > [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > [email protected]: See https://github.com/lydell/source-map-url#deprecated
warning vite-plugin-svg-icons > svg-baker > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
warning vue-tsc > [email protected]: 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/[email protected]: WARNING: This project has been renamed to @johnsoncodehk/html2pug. Install using @johnsoncodehk/html2pug instead.
warning vue-tsc > vscode-vue-languageservice > [email protected]: WARNING: This project has been renamed to @volar/pug-language-service. Install using @volar/pug-language-service instead.
warning vue-tsc > vscode-vue-languageservice > [email protected]: 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/[email protected]: 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] === ""   这种判断方法

扫描二维码关注公众号,回复: 14830616 查看本文章
"被查询字符串".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

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

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

猜你喜欢

转载自blog.csdn.net/qq_43185384/article/details/127509713