React-native-windows: Error: Cannot find module '@react-native-community/cli/build/tools/copyAndReplace'

Created on 10 Apr 2020  ·  11Comments  ·  Source: microsoft/react-native-windows

Environment


react-native -v:

  • react-native-cli: 2.0.1
  • react-native: 0.61.5

react-native run-windows --info:

System:

  • OS: Windows 10 10.0.18363
  • CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  • Memory: 2.48 GB / 7.90 GB
    Binaries:
  • Node: 12.16.2 - C:\Program Files\nodejs\node.EXE
  • npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
  • react: 16.9.0 => 16.9.0
  • react-native: 0.61.5 => 0.61.5
  • react-native-windows: ^0.61.3 => 0.61.3
  • rnpm-plugin-windows: ^0.6.1 => 0.6.1
    Installed UWP SDKs:
  • 10.0.10240.0
  • 10.0.10586.0
  • 10.0.15063.0
  • 10.0.16299.0
  • 10.0.17134.0
  • 10.0.17763.0
  • 10.0.18362.0

Target Env:

  • Target Platform Version(s): 10.0.18362

  • Target Device(s): Desktop

  • Visual Studio Version: Visual Studio 2017

  • Build Configuration: Debug

Steps to Reproduce

(Write your steps here:)

  1. npx react-native init react_native_windows_todo --version ^0.61.5
  2. cd react_native_windows_todo
  3. npx react-native-windows-init

Expected Behavior

The expecting project has to create and run successfully.

Actual Behavior

But, getting an error while creating a project

[email protected] successfully installed.
Cannot find module '@react-native-community/cli/build/tools/copyAndReplace'
Require stack:

  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-commonindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-windowsindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generate-windows.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\src\windows.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windowsindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\react-native.config.js
  • F:\Vs Apps\react_native_windows_todo\node_modulesimport-freshindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\loaders.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\createExplorer.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\distindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\configindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\commandsinstallinstall.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\commandsindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\buildindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\cli.js
  • c:\Users\Admin\AppData\Roaming\npm\node_modules\react-native-cliindex.js
    Error: Cannot find module '@react-native-community/cli/build/tools/copyAndReplace'
    Require stack:
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-commonindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-windowsindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generate-windows.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\src\windows.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windowsindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\react-native.config.js
  • F:\Vs Apps\react_native_windows_todo\node_modulesimport-freshindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\loaders.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\createExplorer.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\distindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\configindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\commandsinstallinstall.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\commandsindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\buildindex.js
  • F:\Vs Apps\react_native_windows_todo\node_modules\react-native\cli.js
  • c:\Users\Admin\AppData\Roaming\npm\node_modules\react-native-cliindex.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object. (F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-commonindex.js:4:24)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-common\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generator-windows\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native-windows\local-cli\generate-windows.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\src\windows.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\rnpm-plugin-windows\react-native.config.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\import-fresh\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\loaders.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\createExplorer.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\cosmiconfig\dist\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\config\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\install\install.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js',
    'F:\Vs Apps\react_native_windows_todo\node_modules\react-native\cli.js',
    'c:\Users\Admin\AppData\Roaming\npm\node_modules\react-native-cli\index.js'
CLI Invalid Triage Author Feedback bug no-recent-activity

Most helpful comment

@tejaat1995

I can successfully able to run npx react-native-windows-init.
Try the following:

npm i --save-dev @react-native-community/cli

All 11 comments

+1

@tejaat1995

I can successfully able to run npx react-native-windows-init.
Try the following:

npm i --save-dev @react-native-community/cli

@saikksub Can you share your environment issue as well? (although now I guess it's not reproing for you?)

The CLI version you should get is version 3.
This might be due to a global install of react-native. That used to be standard practice but can cause issues like this which is why it's no longer the recommended practice.
Try:
npm uninstall -g react-native

+1

@tejaat1995

I can successfully able to run npx react-native-windows-init.
Try the following:

npm i --save-dev @react-native-community/cli

Saving @react-native-community/cli as a dev dependency and then retrying the command worked for me too.

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 14 days of this comment.

@saikksub Can you share your environment issue as well? (although now I guess it's not reproing for you?)

The CLI version you should get is version 3.
This might be due to a global install of react-native. That used to be standard practice but can cause issues like this which is why it's no longer the recommended practice.
Try:
npm uninstall -g react-native

FYI: I have the same issue and do not have react-native installed globally.

I installed the @react-native-community/cli as a dev dep as suggested and now it works.
it installed version 4.8.0 while react-native has a dependency on ^3.0.0 and installed version 3.2.1

npx: installed 114 in 5.662s
Reading application name from package.json...
Reading react-native version from node_modules...
Reading react-native version from node_modules...
Latest matching version of react-native-windows for [email protected] is [email protected]
Installing react-native-windows@^0.61.0-0...

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 14 days of this comment.

@tejaat1995

I can successfully able to run npx react-native-windows-init.
Try the following:

npm i --save-dev @react-native-community/cli

This worked for me

@tejaat1995

I can successfully able to run npx react-native-windows-init.
Try the following:

npm i --save-dev @react-native-community/cli

This works.

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 14 days of this comment.

Was this page helpful?
0 / 5 - 0 ratings