ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 50 forks source link

Unable to resolve module #31

Closed rochapablo closed 6 years ago

rochapablo commented 6 years ago

I don't know what happened, it was working but because I had to re-install my packages I can't get this working anymore.

Unable to resolve module `~src/App` from `/.../MyApp/index.android.js`: Module does not exist in the module map

I tried

rm yarn.lock package-lock.json && rm -rf node_modules && yarn install

// and

react-native start --transformer node_modules/react-native-typescript-transformer/index.js --sourceExts ts,tsx

// and

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.

but it still the same

follow my tsconfig

{
    "compilerOptions": {
        "target": "esnext",
        "moduleResolution": "node",
        "jsx": "react",
        "noEmit": true,
        "allowSyntheticDefaultImports": true,
        "noImplicitAny": false,
        "preserveConstEnums": true,
        "allowJs": true,
        "checkJs": false,
        "sourceMap": true,
        "noImplicitReturns": true,
        "noUnusedParameters": true,
        "noUnusedLocals": true,
        "baseUrl": ".",
        "paths": {
            "~src/*" : ["src/*"],
            "~components/*" : ["src/components/*"]
        }
    },
    "filesGlob": [
        "typings/index.d.ts",
        "src/**/*.ts",
        "src/**/*.js"
    ],
    "types": [
        "react",
        "react-native",
        "jest"
    ],
    "exclude": [
        "android",
        "ios",
        "node_modules"
    ],
    "compileOnSave": true
}
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",

// devDependencies

"@types/react": "^16.0.7",
"@types/react-native": "^0.48.7",
"react-native-typescript-transformer": "^1.1.4",
ds300 commented 6 years ago

how have you configured react-native to support the tilde (~) character in absolute paths? I've never seen that before

rochapablo commented 6 years ago

Ouch!

I cant say where I took that (~) from; but as I was working with and was all working so, I haven't thought that could be the problem.

And indeed, was remove those tilde and all went back to work.

Thank you.

rochapablo commented 6 years ago

@ds300, shouldn't this also be working on IOS?

I'm getting the same error, while on Android everything it's working.

error: bundling failed: "Unable to resolve module `services/persist/actions` from `/MyApp/src/store.js`: Module does not exist in the module map
"baseUrl": ".",
"paths": {
   ...
   "services/*" : ["./src/services/*"]
}
ds300 commented 6 years ago

Remember that react-native and TypeScript use individual methods to find files with absolute paths. react-native can't read the configuration in your tsconfig.json.

If you put a file in src/services/persist/actions and you want to import it with the string "services/persist/actions" then you need to put a package.json file containing only {"name": "services"} at src/services/package.json