question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build test with Jest fails with `Could not locate module @/something`

See original GitHub issue

I’m building an app with vuejs and testing with jest and running the tests locally works, but on circleci fails with the error

FAIL  test/unit/specs/components/ui/MessageUI.spec.js
   Test suite failed to run
    Configuration error:
    Could not locate module @/components/ui/MessageUi (mapped as /home/circleci/repo/src/components/ui/MessageUi)
    Please check:
    "moduleNameMapper": {
      "/^@\/(.*)$/": "/home/circleci/repo/src/$1"
    },
    "resolver": undefined

is not finding the component with the alias @. 😠

the failing component require:

import Component from '@/components/ui/MessageUi'

in the same folder I have another test, working, with:

import Component from '@/components/ui/TabsUi'

build: #39 repo: poc-cms test: MessageUI.spec.js#L3 component MessageUI.vue jest config for the @ alias : jest.conf.js#L11

the closest issue related, on jest: https://github.com/facebook/jest/issues/1290

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

52reactions
sinaacommented, Mar 13, 2018

We faced the same issue which surprisingly passed on Windows and not on Linux (or circleci).

It turned out to be a simple file-name case sensitivity. The component’s filename was by mistake componentName rather than ComponentName.

23reactions
letanurecommented, Jan 2, 2018

changing the moduleNameMapper on jest.conf.js to remove the src breaks all tests

from


moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1'
  },

to

moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1'
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Jest error Could not locate module .... mapped as
For me I did not finish reading the Jest docs and thought that <rootDir> was some sort of placeholder for my root directory...
Read more >
Build test with Jest fails with `Could not locate module ...
I'm building an app with vuejs and testing with jest and running the tests locally works, but on circleci fails with the error...
Read more >
Angular >=13 | jest-preset-angular - GitHub Pages
Jest ESM support with Angular 13 is new and may have issues. ... Cannot find modules error when importing any deep paths from...
Read more >
Configuring Jest
All modules used in your tests will have a replacement implementation, ... If the file specified by path is not found, an error...
Read more >
test suite failed to run cannot find module jest - You.com
I used Create React App to make a new project, and now i try to implement each feature i will need. I am...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found