#absolute imports not working

1 messages · Page 1 of 1 (latest)

olive bluff
#

this is my jsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"]
    }
  }
}

and when I want to import using import ShiftMaterial from "@components/three/material/ShiftMaterial"; I get this error:

Failed to resolve import "@components/three/material/ShiftMaterial" from "src/components/three/houses/first/Object1.jsx". Does the file exist?

although the path is correct
Am i missing something?

gentle palmBOT
#

Hi @olive bluff. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems like you have correctly set up absolute imports in your jsconfig.json file. However, if you're using Jest for testing, you might need to configure Jest to resolve the imports by matching the paths option in the jsconfig.json file with the moduleNameMapper option in the jest.config.js file.

Here's an example of how to do this:

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

This configuration tells Jest to replace @components/... with <rootDir>/src/components/... when it encounters such an import statement.

If you're not using Jest or if this doesn't solve your problem, there might be other issues at play that are not covered in the provided extracts. In that case, I would recommend checking the official Next.js documentation or their community forums for further assistance.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: