Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'entities/lib/maps/entities.json' #2404

Closed
2 of 13 tasks
Innei opened this issue Jun 13, 2020 · 8 comments
Closed
2 of 13 tasks

Cannot find module 'entities/lib/maps/entities.json' #2404

Innei opened this issue Jun 13, 2020 · 8 comments
Labels

Comments

@Innei
Copy link

Innei commented Jun 13, 2020

Current behavior

FAIL  __tests__/header.spec.tsx
  ● Test suite failed to run

    Cannot find module 'entities/lib/maps/entities.json' from 'node_modules/htmlparser2/lib/Tokenizer.js'

    Require stack:
      node_modules/htmlparser2/lib/Tokenizer.js
      node_modules/htmlparser2/lib/Parser.js
      node_modules/htmlparser2/lib/index.js
      node_modules/cheerio/lib/parse.js
      node_modules/cheerio/lib/cheerio.js
      node_modules/cheerio/index.js
      node_modules/enzyme/build/Utils.js
      node_modules/enzyme/build/ReactWrapper.js
      node_modules/enzyme/build/index.js
      enzyme.js

and my jest.config.js

/*
 * @Author: Innei
 * @Date: 2020-06-13 11:08:49
 * @LastEditTime: 2020-06-13 12:15:45
 * @LastEditors: Innei
 * @FilePath: /mx-web/jest.config.js
 * @Coding with Love
 */
const path = require('path')
module.exports = {
  roots: ['<rootDir>/'],
  rootDir: './',
  moduleFileExtensions: ['ts', 'tsx', 'js'],
  collectCoverageFrom: [
    '**/*.{js,jsx,ts,tsx}',
    '!**/*.d.ts',
    '!**/node_modules/**',
  ],
  testPathIgnorePatterns: ['/node_modules/', '/.next/'],
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
    '^.+\\.(js|jsx)$': '<rootDir>/node_modules/babel-jest',
    '^.+\\.css$': '<rootDir>/configs/jest/cssTransform.js',
  },
  testMatch: ['**/*.(test|spec).(ts|tsx)'],
  coveragePathIgnorePatterns: ['/node_modules/', 'enzyme.js'],
  setupFilesAfterEnv: ['<rootDir>/enzyme.js'],
  coverageReporters: ['json', 'lcov', 'text', 'text-summary'],
  globals: {
    'ts-jest': {
      useBabelrc: true,
      tsConfigFile: 'jest.tsconfig.json',
    },
  },
  transformIgnorePatterns: [
    '/node_modules/',
    '^.+\\.module\\.(css|sass|scss)$',
  ],
  moduleNameMapper: {
    '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/__mocks__/mocks.js',
    '\\.(css|less|scss)$': '<rootDir>/__mocks__/mocks.js',
  },
  moduleDirectories: [path.resolve(__dirname, 'node_modules'), '<rootDir>/'],
}

please help me, thank you!

Expected behavior

test pass

Your environment

macOS 10.15.2
node 12@latest

API

  • shallow
  • mount
  • render

Version

library version
enzyme ^3.11.0
react 16.3.1
react-dom 16.13.1
react-test-renderer 16.13.1
adapter (below) 16

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Jun 13, 2020

You forgot to include .json in your moduleFileExtensions.

@ljharb ljharb closed this as completed Jun 13, 2020
@ljharb ljharb added the invalid label Jun 13, 2020
@SabrinaFZ
Copy link

You forgot to include .json in your moduleFileExtensions.

I have the same problem and I have included the .json

@ljharb
Copy link
Member

ljharb commented Oct 6, 2020

@SabrinaFZ can you provide the same info that the OP provided, either here or in a new issue?

@goldEli
Copy link

goldEli commented Oct 16, 2020

You forgot to include .json in your moduleFileExtensions.

I have the same problem and I have included the .json

my jest.config.js:
image

my file directory structure:

- src
- config
  - jest.config.js
  - cssTransfom.js
  - enzymeConfig.js
  - fileTransform.js 

current behavior:
image

@ljharb
Copy link
Member

ljharb commented Oct 16, 2020

Why is the folder in node modules called “[email protected]@htmlparser2”? That’s not a valid package name, and version numbers aren’t part of the file structure.

@goldEli
Copy link

goldEli commented Oct 16, 2020

Why is the folder in node modules called “[email protected]@htmlparser2”? That’s not a valid package name, and version numbers aren’t part of the file structure.

thank you so much @ljharb
I used cnpm to install my packages before, and the problem was fixed after swtiching to npm
maybe cnpm bug

@ljharb
Copy link
Member

ljharb commented Oct 16, 2020

Definitely. Anything that works with npm but doesn't work with an alternative package manager is a bug in that package manager.

@gyanendraknojiya
Copy link

npm i htmlparser2 works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants