npm包弃用警告与create-react-app全局卸载无效问题求助
解决create-react-app模板缺失及依赖弃用问题
问题说明
执行npm安装时出现大量依赖包弃用警告,同时提示**"A template was not provided. This is likely because you're using an outdated version of create-react-app."**,已尝试卸载全局create-react-app但问题未解决。
相关警告片段
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm warn deprecated @babel/plugin-proposal-numeric-separator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead. npm warn deprecated @babel/plugin-proposal-private-methods@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-methods instead. npm warn deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead. npm warn deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm warn deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead npm warn deprecated 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 npm warn deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead. npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser npm warn deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead npm warn deprecated q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. npm warn deprecated npm warn deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead npm warn deprecated domexception@2.0.1: Use your platform's native DOMException instead npm warn deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead npm warn deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin. npm warn deprecated workbox-cacheable-response@6.6.0: workbox-background-sync@6.6.0 npm warn deprecated workbox-google-analytics@6.6.0: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is no longer being maintained npm warn deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. added 1483 packages, and audited 1484 packages in 53s 262 packages are looking for funding run `npm fund` for details 8 vulnerabilities (2 moderate, 6 high) To address all issues, run: npm audit fix Run `npm audit` for details. A template was not provided. This is likely because you're using an outdated version of create-react-app. Please note that global installs of create-react-app are no longer supported. You can fix this by running npm uninstall -g create-react-app or yarn global remove create-react-app before using create-react-app again.
解决方案
1. 彻底清除全局残留的create-react-app
- 检查全局是否仍有残留:
npm list -g create-react-app - 若存在残留,再次卸载:
npm uninstall -g create-react-app # 或用yarn yarn global remove create-react-app - 清理npm缓存:
npm cache clean --force
2. 使用npx直接调用最新版create-react-app
官方已废弃全局安装方式,必须通过npx调用最新版本创建项目:
npx create-react-app@latest 你的项目名 # 或用yarn yarn create react-app 你的项目名
3. 手动指定模板(若仍提示模板缺失)
如果上述命令仍报错,手动指定官方默认模板:
npx create-react-app@latest 你的项目名 --template cra-template # TypeScript项目用这个 npx create-react-app@latest 你的项目名 --template typescript
4. 处理依赖弃用与漏洞
项目创建完成后,进入项目目录:
- 升级所有依赖到最新版:
npm update - 修复漏洞:
npm audit fix - 针对特定弃用包,手动替换为推荐版本(比如将babel的
proposal系列插件换成transform系列,升级rimraf到v4+等)。
内容的提问来源于stack exchange,提问作者saisowmya nandyala
相关产品推荐
相关产品推荐

