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.

importing from src

See original GitHub issue

Hi,

Apologies as i am sure this a simple question but …

When i import from src e.g.

import useAsyncTaskAxios from 'react-hooks-async/src/use-async-task-axios'

this works fine in my code but not in my tests

i get SyntaxError: Unexpected identifier

guessing its because the ES6 modules not compiling but not sure how to modify my jest config to sort it out. If i import from dist then the type information is not available?

jest.config.js

module.exports = {
    "roots": [
      "<rootDir>/src"
    ],
    "transform": {
      "^.+\\.tsx?$": "ts-jest"
    },
    "moduleDirectories": ["node_modules", "src"],
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ],
    "reporters": [ "default", "jest-junit" ]
  }

Any thoughts welcome thanks, Ed

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dai-shicommented, Jun 27, 2019

Cool. Good to hear that.

I’m thinking of adding another breaking change in the API for v3. Please be patient.

1reaction
dai-shicommented, Jun 27, 2019

Published 3.0.0-alpha.0. Please give it a try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to properly import between src and test modules
You need to either configure your sys.path, or use import src.file1 If you rename src to something like my_module it would make more...
Read more >
import - JavaScript - MDN Web Docs - Mozilla
In order to use the import declaration in a source file, the file must be interpreted by the runtime as a module. In...
Read more >
Offer a way to import files relative to `src/` · Issue #581 - GitHub
It would be possible to configure webpack so we could import files from src/ just like import 'testUtils/myMock or maybe src/testUtils/myMock by ...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
importlib — The implementation of import — Python 3.11.1 ...
One is to provide the implementation of the import statement (and thus, by extension, the __import__() function) in Python source code.
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