从__tests__目录导出时无法解析模块

时间:2019-01-08 15:15:13

标签: typescript react-native jestjs

说明

我有一些位于__tests__目录中的帮助程序模块,这些模块也已导出。这是我的目录结构。有两个软件包A和B。我正在从A的__tests__目录中导出fileA并尝试在B内部使用它。

A
├── dist
├── node_modules
├── src
│   ├── __tests__
│   │   ├── __helpers__
│   │   │   ├── fileA.ts
│   │   └── integration.test.ts

B
├── dist
├── node_modules
├── src
│   ├── __tests__
│   │   └── integration.test.ts

但是它无法解析模块,并引发以下错误:

Loading dependency graph, done.
error: bundling failed: Error: Unable to resolve module `./__tests__/__helpers__/fileA` from 
`/Users/xyz/project/packages/A/dist/index.js`: 
The module `./__tests__/__helpers__/fileA` could not be found from `/Users/xyz/project/packages/A/dist/index.js`. Indeed, none of these files exist:

* `/Users/xyz/project/packages/A/dist/__tests__/__helpers__/fileA(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`
* `/Users/xyz/project/packages/A/dist/__tests__/__helpers__/fileA/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`

但是文件确实存在。

环境

React Native Environment Info:
System:
  OS: macOS 10.14.2
  CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  Memory: 99.84 MB / 8.00 GB
  Shell: 5.3 - /bin/zsh
Binaries:
  Node: 11.1.0 - ~/.nvm/versions/node/v11.1.0/bin/node
  Yarn: 1.12.3 - /usr/local/bin/yarn
  npm: 6.4.1 - ~/.nvm/versions/node/v11.1.0/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
  iOS SDK:
    Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
  Android SDK:
    Build Tools: 22.0.1, 23.0.1, 25.0.0, 25.0.2, 26.0.0, 26.0.2
    API Levels: 19, 21, 23, 24, 25, 26
IDEs:
  Android Studio: 3.1 AI-173.4720617
  Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
  react: 16.5.0 => 16.5.0
  react-native: 0.57.2 => 0.57.2
npmGlobalPackages:
  react-native-cli: 2.0.1

我尝试过的事情

  • 我尝试清洁纱线和地铁捆扎机的缓存
  • 删除了node_modules,清除了守望者的状态

0 个答案:

没有答案