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.

Component directory cannot be resolved

See original GitHub issue

Im using CRA + TypeScript and wanted to test out playroom but immediately run into this error: (node:39309) UnhandledPromiseRejectionWarning: Error: Cannot find module './src/Components'

playroom.config.js

module.exports = {
  components: './src/Components',
  outputPath: './build/playroom',
  typeScriptFiles: [
    'src/Components/**/*.{ts,tsx}',
    '!**/node_modules',
  ],
};

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve"
  },
  "include": [
    "src"
  ]
}

Any ideas about this? 😞

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
GoodGuyMarcocommented, Jan 31, 2020

Thank you for your detailed explanation. I managed to get it running now. Seems like it was me misunderstanding the documentation. Two things that were not entirely clear to me:

  1. By example components: './src/components' it is not clear that it should point to a file containing exported components. I thought it should point to my component directory.
  2. Your “TypeScript Support” section does not mention that extra loaders are needed in webpackConfig in order to include components written in TypeScript.

Anyways, maybe it is just my lack of knowledge 😄 Thanks for this awesome project. Will start playing with it right now 👍

3reactions
michaeltarantocommented, Jan 30, 2020

Thanks for that, makes it a lot clearer. Here is the list i worked through to get that example working:

Config issues

The themes and FrameComponent are optional in the playroom config and the paths specified dont exist, so i removed these config values.

The components path is resolved based on your webpack config. Out of the box playroom only configured react and jsx support so doing anything more than playing with react requires passing a webpackConfig that allows playroom to run your code.

Component file

This isn’t being found by webpack because it’s is not configured to resolve ts/tsx extensions out of the box. You can do this by providing your own webpack config (see our typescript example).

Your components file is expected to export a single object or a series of named exports

I recommend pointing at a file the exports your components, eg:

export { default as Text } from '../Text'; // Re-exporting a default export
export { Button } from '../Button'; // Re-exporting a named export
// etc...

The main issue i see here is you need to provide playroom with the webpack config so it knows how to load your components.

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React cannot resolve module in my directory
Your directory path is wrong. Three dots (".../") is not a valid relative path. It should be: import '../../static/css/app_style.css'.
Read more >
Cannot resolve file or directory entry.component.css
I am doing the Nesting Components part of Angular Basics, and there is one problem ... Cannot resolve file or directory entry.component.css.
Read more >
TypeScript: Documentation - Module Resolution
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Cannot resolve directory '@' error in PhpStorm with Vite
I did it like you said and restarted IDE, but I still get the same thing. this `components` directory is under ./resources/js/components.
Read more >
LWC compiler cannot resolve import
If the component has missing files or invalid import statements, that is reported at the time of deploying the component. No such errors...
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