Cannot find module '../../Themes' from 'RoundButton.js' - Working OK locally

version: 2
jobs:
  build:
    working_directory: ~/project
    docker:
      - image: circleci/node:8
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          - v1-dependencies-
      - run: yarn install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - run: yarn test

I’m running it against a React Native project. Locally it runs well, but in CircleCI:

#!/bin/bash -eo pipefail
yarn test
yarn run v1.3.2
$ jest --coverage
 FAIL  __tests__/Components/Shared/RoundButton.js
  ● Test suite failed to run

    Cannot find module '../../Themes' from 'RoundButton.js'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
      at Object.<anonymous> (src/Components/Shared/RoundButton.js:12:13)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.514s
Ran all test suites.
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                   |
----------|----------|----------|----------|----------|-------------------|
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code 1

Can anyone help me on this?

It may be worth checking out a new copy on your local machine, in case you have files in your working directory that would not be present in a fresh checkout.

Also, re-run the CircleCI build with the SSH option, so you can do some debugging in situ. Treat “Cannot find module” remotely as if it were a local problem - how would you investigate this in Yarn or Jest normally?

1 Like

Indeed there’ something missing.
But still can’t replicate the error locally. Locally the snapshots didn’t match

— EDIT —

I cloned in a new folder and ran the tests. I had some difference on the snapshots, which makes no sense to me, but the path error doesn’t happen.

.babelrc

{
  "presets": ["react-native"],
  "plugins": ["transform-decorators-legacy"]
}

.eslintrc

{
  "env": {
    "jest/globals": true
  },
  "parser": "babel-eslint",
  "plugins": ["jest"],
  "extends": [
    "standard",
    "standard-react",
    "plugin:jest/recommended"
  ],
  "rules": {
    "react/prop-types": 1
  }
}

Package.json

{
  "version": "0.0.8",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "yarn lint || jest",
    "storybooking": "start -p 7007",
    "lint": "./node_modules/eslint/bin/eslint.js ./src/**/*.js -f node_modules/eslint-formatter-summary"
  },
  "dependencies": {
    "invariant": "^2.2.2",
    "mobx": "^3.4.1",
    "mobx-persist": "^0.4.1",
    "mobx-react": "^4.3.5",
    "mobx-remotedev": "^0.2.8",
    "moment": "^2.20.1",
    "qs": "^6.5.1",
    "react": "16.0.0",
    "react-native": "0.51.0",
    "react-native-collapse-view": "^1.0.0",
    "react-native-config": "^0.11.2",
    "react-native-fbsdk": "^0.7.0",
    "react-native-firebase": "3.2.5",
    "react-native-gesture-handler": "^1.0.0-alpha.41",
    "react-native-linear-gradient": "^2.4.0",
    "react-native-modal-datetime-picker": "^4.13.0",
    "react-native-picker-dropdown": "^0.1.1",
    "react-native-tab-view": "^0.0.74",
    "react-navigation": "1.0.0-beta.21",
    "react-timeout": "^1.0.1",
    "sort-by": "^1.2.0"
  },
  "devDependencies": {
    "@storybook/addon-actions": "^3.3.3",
    "@storybook/addon-links": "^3.3.3",
    "@storybook/react-native": "^3.3.3",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.2.2",
    "babel-jest": "^22.4.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "eslint": "^4.18.1",
    "eslint-config-standard": "^11.0.0",
    "eslint-config-standard-react": "^6.0.0",
    "eslint-formatter-summary": "^1.0.2",
    "eslint-plugin-import": "^2.9.0",
    "eslint-plugin-jest": "^21.12.2",
    "eslint-plugin-node": "^6.0.0",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-react": "^7.7.0",
    "eslint-plugin-standard": "^3.0.1",
    "firebase-mock": "^2.0.25",
    "jest": "^22.4.2",
    "prop-types": "^15.6.0",
    "react-dom": "16.0.0",
    "react-test-renderer": "16.0.0"
  },
  "jest": {
    "preset": "react-native",
    "collectCoverage": true,
    "collectCoverageFrom": [
      "src/**/*.js"
    ]
  },
  "rnpm": {
    "assets": [
      "./src/Assets/Fonts/"
    ]
  },
  "standard": {
    "plugins": [
      "flowtype"
    ],
    "parser": "babel-eslint"
  }
}

I had the same problem. In my case the problem was with case. Localhost was ignoring case, and Circle didn’t

Problematic line contained someModule, but module name was somemodule:
import Rule from ‘@models/someModule/Rule’;

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.