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

import.meta not available in Jest #44

Open
timkinnane opened this issue Jan 3, 2022 · 2 comments
Open

import.meta not available in Jest #44

timkinnane opened this issue Jan 3, 2022 · 2 comments

Comments

@timkinnane
Copy link

timkinnane commented Jan 3, 2022

Thanks for the package, it performs well and is simple to set up. ❤️

I'm using it as a Jest transformer and trying to test a function written in Typescript to read a package JSON file:

import { createRequire } from 'module'
import { resolve } from 'path'

export const requirePackage = (path: string) =>
  createRequire(import.meta.url)(resolve(path, 'package.json'))

I get an error from import.meta.url being undefined.

Possibly related issue in TS-Jest? kulshekhar/ts-jest#1174

@timkinnane
Copy link
Author

My configs...

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src",
    "module": "esnext",
    "moduleResolution": "Node",
    "lib": ["ESNext"],
    "allowJs": true,
    "checkJs": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "skipLibCheck": true,
    "strict": true
  }
}

jest.config.mjs

export default {
  testEnvironment: 'node',
  extensionsToTreatAsEsm: ['.ts'],
  moduleFileExtensions: [ 'ts', 'tsx', 'mjs', 'js', 'jsx', 'json', 'node' ],
  transformIgnorePatterns: ['/node_modules/.*\\.js$'],
  transform: {
    '\\.(ts|tsx)?$': 'esbuild-runner/jest',
  }
}

@kulkarnipradnyas
Copy link

any updates?

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

No branches or pull requests

2 participants