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

[Bug]: 使用import.meta.glob报错TypeError: {(intermediate value)}.glob is not a function #13955

Closed
chengup-git opened this issue Feb 25, 2023 · 4 comments

Comments

@chengup-git
Copy link

Version

29.4.3

Steps to reproduce

在jest.mock文件中使用到import.meta.glob

Expected behavior

正常运行

Actual behavior

image

Additional context

jest.config.js

module.exports = {
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
    '\\.(css|less)$': '<rootDir>/tests/__mocks__/css.ts',
  },
  moduleFileExtensions: ['ts', 'js', 'jsx', 'tsx', 'json', 'vue'],
  transform: {
    '^.+\\.vue$': require.resolve('@vue/vue3-jest'),
    '^.+\\.tsx?$': [
      require.resolve('ts-jest'),
      {
        diagnostics: {
          ignoreCodes: [1343],
        },
        astTransformers: {
          before: [
            {
              path: 'ts-jest-mock-import-meta',
            },
          ],
        },
      },
    ],
    '.+\\.(css|style|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
      require.resolve('jest-transform-stub'),
    '^.+\\.[jt]sx?$': require.resolve('babel-jest'),
  },
  testMatch: ['**/tests/unit/**/*.spec.ts'],
  transformIgnorePatterns: ['/node_modules/'],
  // serializer for snapshots
  snapshotSerializers: ['jest-serializer-vue'],
  testEnvironmentOptions: {
    customExportConditions: ['node', 'node-addons'],
  },
}

package.json

"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@types/jest": "^29.4.0",
"@types/node": "18.8.0",
"@vue/test-utils": "^2.3.0",
"@vue/vue3-jest": "29.2.2",
"babel-jest": "^29.3.1",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"jest-serializer-vue": "^2.0.2",
"jest-transform-stub": "^2.0.0",
"ts-jest": "^29.0.5",
"ts-jest-mock-import-meta": "^1.0.0",

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12500
  Binaries:
    Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.4.3 => 29.4.3
@mrazauskas
Copy link
Contributor

Could you describe the problem in English, pease? Minimal reproduction repo would be also helpful.

Probably this is just a configuration problem. For example, you are transforming tsx?$ with ts-jest and [jt]sx?$ with babel-jest. Transformation result for ts and tsx file might become unpredictable here. If you transform those file with ts-jest, there is no need to pass them to babel-jest. Without a reproduction it is hard to say what your project needs.

@SimenB
Copy link
Member

SimenB commented Feb 25, 2023

import.meta.glob is a vite extension, jest doesn't support it. You'd need a babel plugin (or something) which changes it to something else

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2023
@chengup-git
Copy link
Author

可以在这个项目中运行 npm run jest https://replit.com/@chengup-git/jest

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants