create-react-app 使用脚本版本3.4.1和类型模板破坏的BootstrappingReact应用程序

0wi1tuuw  于 6个月前  发布在  React
关注(0)|答案(1)|浏览(64)

描述bug

由于react-calendar不支持React版本>16,我希望能够使用旧的scripts-version引导一个React应用。然而,当运行create-react-appscripts-version 3.4.1和TypeScript模板时,执行将失败于Error: Cannot find module 'cra-template-typescript'

你尝试恢复依赖项了吗?

(不适用)

你在用户指南中搜索了哪些术语?

两个结果都没有帮助。

环境

$ npx create-react-app --info

Environment Info:

  current version of create-react-app: 5.0.1
  running from /Users/anticom/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

  System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.4.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.12.1 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 103.0.5060.53
    Edge: Not Found
    Firefox: 101.0
    Safari: 15.5
  npmPackages:
    react: Not Found
    react-dom: Not Found
    react-scripts: Not Found
  npmGlobalPackages:
    create-react-app: Not Found

重现步骤

  1. npx create-react-app my-example-app --scripts-version 3.4.1 --template typescript

预期行为

我希望得到一个带有TypeScript支持的React 16应用。

实际行为

$ npx create-react-app my-example-app --scripts-version 3.4.1 --template typescript

Creating a new React app in /path/to/my-example-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript...

added 1621 packages in 2m

106 packages are looking for funding
  run `npm fund` for details
node:internal/modules/cjs/loader:949
  throw err;
  ^

Error: Cannot find module 'cra-template-typescript'
Require stack:
- /path/to/my-example-app/node_modules/react-scripts/scripts/init.js
- /path/to/my-example-app/[eval]
    at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at module.exports (/path/to/my-example-app/node_modules/react-scripts/scripts/init.js:110:13)
    at [eval]:3:14
    at Script.runInThisContext (node:vm:130:12)
    at Object.runInThisContext (node:vm:306:38)
    at node:internal/process/execution:76:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60)
    at node:internal/main/eval_string:27:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/path/to/my-example-app/node_modules/react-scripts/scripts/init.js',
    '/path/to/my-example-app/[eval]'
  ]
}

Node.js v18.4.0

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Done.

可复现的演示

(见上文)

r8uurelv

r8uurelv1#

我注意到它似乎没有绑定到typescript模板。如果省略它,我会得到:

npx create-react-app my-example-app --scripts-version 3.4.1

Creating a new React app in /path/to/my-example-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

added 1621 packages in 28s

106 packages are looking for funding
  run `npm fund` for details
node:internal/modules/cjs/loader:949
  throw err;
  ^

Error: Cannot find module 'cra-template'
Require stack:
- /path/to/my-example-app/node_modules/react-scripts/scripts/init.js
- /path/to/my-example-app/[eval]
    at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at module.exports (/path/to/my-example-app/node_modules/react-scripts/scripts/init.js:110:13)
    at [eval]:3:14
    at Script.runInThisContext (node:vm:130:12)
    at Object.runInThisContext (node:vm:306:38)
    at node:internal/process/execution:76:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60)
    at node:internal/main/eval_string:27:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/path/to/my-example-app/node_modules/react-scripts/scripts/init.js',
    '/path/to/my-example-app/[eval]'
  ]
}

Node.js v18.4.0

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Done.

相关问题