Error: Cannot find module './lib/source-map-generator'
Error: Cannot find module './lib/source-map-generator'
我刚刚从 Github、运行 npm install
和 npm start
.
克隆了一个存储库(一个 React Native 项目)
然后 运行 metro bundler 将抛出以下错误:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './lib/source-map-generator'
Require stack:
- D:\ProjectX\node_modules\snapdragon\node_modules\source-map\source-map.js
- D:\ProjectX\node_modules\snapdragon\lib\utils.js
- D:\ProjectX\node_modules\snapdragon\lib\compiler.js
- D:\ProjectX\node_modules\snapdragon\index.js
- D:\ProjectX\node_modules\sane\node_modules\braces\lib\braces.js
- D:\ProjectX\node_modules\sane\node_modules\braces\index.js
- D:\ProjectX\node_modules\sane\node_modules\micromatch\index.js
- D:\ProjectX\node_modules\sane\node_modules\anymatch\index.js
- D:\ProjectX\node_modules\sane\src\common.js
- D:\ProjectX\node_modules\jest-haste-map\build\lib\WatchmanWatcher.js
- D:\ProjectX\node_modules\jest-haste-map\build\index.js
- D:\ProjectX\node_modules\metro-core\src\errors\AmbiguousModuleResolutionError.js
- D:\ProjectX\node_modules\metro-core\src\index.js
- D:\ProjectX\node_modules\metro\src\node-haste\DependencyGraph.js
- D:\ProjectX\node_modules\metro\src\Bundler.js
- D:\ProjectX\node_modules\metro\src\IncrementalBundler.js
- D:\ProjectX\node_modules\metro\src\Server.js
- D:\ProjectX\node_modules\metro\src\shared\output\bundle.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\buildBundle.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\bundle.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\index.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\index.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\index.js
- D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\index.js
- D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js
- D:\ProjectX\node_modules\react-native\cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\ProjectX\node_modules\snapdragon\node_modules\source-map\source-map.js:6:30)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\ProjectX\node_modules\snapdragon\node_modules\source-map\source-map.js',
'D:\ProjectX\node_modules\snapdragon\lib\utils.js',
'D:\ProjectX\node_modules\snapdragon\lib\compiler.js',
'D:\ProjectX\node_modules\snapdragon\index.js',
'D:\ProjectX\node_modules\sane\node_modules\braces\lib\braces.js',
'D:\ProjectX\node_modules\sane\node_modules\braces\index.js',
'D:\ProjectX\node_modules\sane\node_modules\micromatch\index.js',
'D:\ProjectX\node_modules\sane\node_modules\anymatch\index.js',
'D:\ProjectX\node_modules\sane\src\common.js',
'D:\ProjectX\node_modules\jest-haste-map\build\lib\WatchmanWatcher.js',
'D:\ProjectX\node_modules\jest-haste-map\build\index.js',
'D:\ProjectX\node_modules\metro-core\src\errors\AmbiguousModuleResolutionError.js',
'D:\ProjectX\node_modules\metro-core\src\index.js',
'D:\ProjectX\node_modules\metro\src\node-haste\DependencyGraph.js',
'D:\ProjectX\node_modules\metro\src\Bundler.js',
'D:\ProjectX\node_modules\metro\src\IncrementalBundler.js',
'D:\ProjectX\node_modules\metro\src\Server.js',
'D:\ProjectX\node_modules\metro\src\shared\output\bundle.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\buildBundle.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\bundle.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\index.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\index.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\index.js',
'D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\index.js',
'D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js',
'D:\ProjectX\node_modules\react-native\cli.js'
]
}
有人知道如何解决上述问题吗?
提前致谢。
尝试删除 node_modules
并重复 npm 安装或 yarn。
如果还是不行,也许可以尝试删除 package-lock.json/yarn.lock 并重复上述操作。
我刚刚从 Github、运行 npm install
和 npm start
.
然后 运行 metro bundler 将抛出以下错误:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './lib/source-map-generator'
Require stack:
- D:\ProjectX\node_modules\snapdragon\node_modules\source-map\source-map.js
- D:\ProjectX\node_modules\snapdragon\lib\utils.js
- D:\ProjectX\node_modules\snapdragon\lib\compiler.js
- D:\ProjectX\node_modules\snapdragon\index.js
- D:\ProjectX\node_modules\sane\node_modules\braces\lib\braces.js
- D:\ProjectX\node_modules\sane\node_modules\braces\index.js
- D:\ProjectX\node_modules\sane\node_modules\micromatch\index.js
- D:\ProjectX\node_modules\sane\node_modules\anymatch\index.js
- D:\ProjectX\node_modules\sane\src\common.js
- D:\ProjectX\node_modules\jest-haste-map\build\lib\WatchmanWatcher.js
- D:\ProjectX\node_modules\jest-haste-map\build\index.js
- D:\ProjectX\node_modules\metro-core\src\errors\AmbiguousModuleResolutionError.js
- D:\ProjectX\node_modules\metro-core\src\index.js
- D:\ProjectX\node_modules\metro\src\node-haste\DependencyGraph.js
- D:\ProjectX\node_modules\metro\src\Bundler.js
- D:\ProjectX\node_modules\metro\src\IncrementalBundler.js
- D:\ProjectX\node_modules\metro\src\Server.js
- D:\ProjectX\node_modules\metro\src\shared\output\bundle.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\buildBundle.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\bundle.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\index.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\index.js
- D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\index.js
- D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\index.js
- D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js
- D:\ProjectX\node_modules\react-native\cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\ProjectX\node_modules\snapdragon\node_modules\source-map\source-map.js:6:30)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\ProjectX\node_modules\snapdragon\node_modules\source-map\source-map.js',
'D:\ProjectX\node_modules\snapdragon\lib\utils.js',
'D:\ProjectX\node_modules\snapdragon\lib\compiler.js',
'D:\ProjectX\node_modules\snapdragon\index.js',
'D:\ProjectX\node_modules\sane\node_modules\braces\lib\braces.js',
'D:\ProjectX\node_modules\sane\node_modules\braces\index.js',
'D:\ProjectX\node_modules\sane\node_modules\micromatch\index.js',
'D:\ProjectX\node_modules\sane\node_modules\anymatch\index.js',
'D:\ProjectX\node_modules\sane\src\common.js',
'D:\ProjectX\node_modules\jest-haste-map\build\lib\WatchmanWatcher.js',
'D:\ProjectX\node_modules\jest-haste-map\build\index.js',
'D:\ProjectX\node_modules\metro-core\src\errors\AmbiguousModuleResolutionError.js',
'D:\ProjectX\node_modules\metro-core\src\index.js',
'D:\ProjectX\node_modules\metro\src\node-haste\DependencyGraph.js',
'D:\ProjectX\node_modules\metro\src\Bundler.js',
'D:\ProjectX\node_modules\metro\src\IncrementalBundler.js',
'D:\ProjectX\node_modules\metro\src\Server.js',
'D:\ProjectX\node_modules\metro\src\shared\output\bundle.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\buildBundle.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\bundle.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\bundle\index.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\commands\index.js',
'D:\ProjectX\node_modules\@react-native-community\cli-plugin-metro\build\index.js',
'D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\index.js',
'D:\ProjectX\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js',
'D:\ProjectX\node_modules\react-native\cli.js'
]
}
有人知道如何解决上述问题吗?
提前致谢。
尝试删除 node_modules
并重复 npm 安装或 yarn。
如果还是不行,也许可以尝试删除 package-lock.json/yarn.lock 并重复上述操作。