我正在尝试运行一个React Native项目lucy-app
,它通过Yarn管理它的包。在src
目录中有一个utils.js
:
Kurts-MacBook-Pro-2:lucy kurtpeek$ tree lucy-app/src -L 1
lucy-app/src
├── actions.js
├── api.js
├── app.js
├── components
├── containers
└── utils.js
moment
和moment-timezone
都显示在package.json
:
{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
},
"dependencies": {
"moment": "^2.19.0",
"moment-timezone": "^0.5.14",
moment-timezone
中有一个node_modules
目录:
/Users/kurtpeek/Documents/dev/lucy/lucy-app/node_modules
Kurts-MacBook-Pro-2:node_modules kurtpeek$ find . -name 'moment-timezone'
./moment-timezone
utils.js
文件导入moment-timezone
,如下所示:
import moment from 'moment-timezone';
但是,当我尝试运行react-native run-ios
时,出现以下错误:
error: bundling failed: Error: Unable to resolve module `moment-timezone` from `/Users/kurtpeek/Documents/Dev/lucy/lucy-app/src/utils.js`: Module does not exist in the module map or in these directories:
/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf $TMPDIR/react-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf $TMPDIR/haste-map-react-native-packager-*`.
at ModuleResolver.resolveDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:311:1719)
at ResolutionRequest.resolveDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:96:16)
at DependencyGraph.resolveDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/node-haste/DependencyGraph.js:269:4352)
at /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:201:36
at Generator.next (<anonymous>)
at step (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:306)
at /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:536
at new Promise (<anonymous>)
at /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:217
at addDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:92)
BUNDLE [ios, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
根据建议,我已尝试rm -rf node_modules
后跟yarn install
,但我仍然遇到同样的错误。任何想法在这里出了什么问题?