node
naming
ai_generated
true
Cannot find module './my-component' — hyphenated folder misresolved or confused with npm scope
ID: node/require-hyphenated-local-folder
80%Fix Rate
85%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
require('./my-component') works but is confused with npm scoped packages or case-insensitive filesystems create mismatches.
genericWorkarounds
-
90% success Use consistent casing and exact folder name in require/import path
import MyComponent from './my-component/index.js' // explicit exact path
Sources: https://nodejs.org/api/esm.html
-
85% success Configure module aliases in tsconfig/webpack to abstract the hyphenated path
{ "compilerOptions": { "paths": { "@components/*": ["./src/my-component/*"] } } }
Dead Ends
Common approaches that don't work:
-
Change require to use underscore version
90% fail
If the actual folder has hyphens, changing to underscores creates a mismatch
-
Add 'main' field in sub-folder package.json
70% fail
Adding package.json in every sub-folder creates unnecessary complexity for a naming issue