npm - 获取错误 : Cannot find module './src/init' when trying to initialize a react native app

标签 npm react-native npm-install

当我尝试使用命令安装 react native 时 react-native init ProjectName
我得到以下信息:

This will walk you through creating a new React Native project in C:\Users\Xegano\Documents\ProjectName
Installing react-native package from npm...
Setting up new React Native app in C:\Users\Xegano\Documents\ProjectName
module.js:457
    throw err;
    ^

Error: Cannot find module './src/init'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\Xegano\Documents\ProjectName\node_modules\gulp-sourcemaps\index.js:4:9)
    at Module._compile (module.js:556:32)
    at Module._extensions..js (module.js:565:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\Xegano\Documents\ProjectName\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)

为什么会发生这种情况?它以前可以工作,我记得我改变的唯一一件事是 SDK 管理器中的一些包。会是这样吗?

最佳答案

实际上它在我的情况下有效,但我需要将 gulp-sourcemaps 降级到 1.7 版

$ cd MyProject
$ rm -rf node_modules/gulp-sourcemaps
$ npm install gulp-sourcemaps@1.7
$ cd ..
$ react-native init MyProject

关于npm - 获取错误 : Cannot find module './src/init' when trying to initialize a react native app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40030716/

相关文章:

node.js - 在包安装 Node 上显示许可证

ubuntu - Grunt 在本地工作,但不能通过 SSH

javascript - 包含带有 css/js 的前端 npm 包的最佳实践?

android - react native 谷歌登录 api 不工作

ios - 在 VS Code : add configuration for iOS Device to launch. json 中 react native

reactjs - 通过 npm 安装 firebase 时遇到错误 |解析附近时 JSON 输入意外结束

node.js - 在 Node.js 中找到带来另一个依赖的依赖

javascript - 将更新部署到 GitHub 后收到错误 "Cannot find module ' fs/promises'"

canvas - 尝试安装 Canvas 时找不到 cario install 命令的 Gulp 问题

javascript - 在 React Native 中使 View 为父级的 80% 宽度