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.

Error in tns run android - Failed to find module ".", relative to app/tns_modules

See original GitHub issue

Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo?

I asked about it on the forum.

Tell us about the problem

Please, ensure your title is less than 63 characters long and starts with a capital letter. I’m getting this error after updating my project.

Error: com.tns.NativeScriptException: Failed to find module: “.”, relative to: app/tns_modules/

If I open the generated javascript files to see where it is complaining I see this:

var _1 = require(".");

Which platform(s) does your issue occur on?

Android - problem ios builds fine

Please provide the following version numbers that your issue occurs with:

  • CLI: (run tns --version to fetch it) 4.1.2

  • Cross-platform modules: (check the ‘version’ attribute in the node_modules/tns-core-modules/package.json file in your project) “tns-core-modules”: “^4.1.1”,

  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the package.json file of your project)

"tns-ios": {
      "version": "4.1.1"
    },
    "tns-android": {
      "version": "4.1.3"
    }
  • Plugin(s): (look for the version number in the package.json file of your project)
"dependencies": {
    "@angular/animations": "~6.0.6",
    "@angular/common": "~6.0.6",
    "@angular/compiler": "~6.0.6",
    "@angular/core": "~6.0.6",
    "@angular/forms": "~6.0.6",
    "@angular/http": "~6.0.6",
    "@angular/platform-browser": "~6.0.6",
    "@angular/platform-browser-dynamic": "~6.0.6",
    "@angular/router": "~6.0.6",
    "async-await": "^0.1.40",
    "lodash": "^4.17.10",
    "moment": "^2.22.0",
    "nativescript-angular": "^6.0.6",
    "nativescript-audio": "^4.3.5",
    "nativescript-drop-down": "^4.0.1",
    "nativescript-orientation": "^2.2.0",
    "nativescript-theme-core": "^1.0.4",
    "nativescript-ui-listview": "3.5.9",
    "nativescript-ui-sidedrawer": "^4.1.1",
    "nativescript-unit-test-runner": "^0.3.4",
    "nativescript-videoplayer": "^4.1.0",
    "nativescript-webview-interface": "^1.4.2",
    "nativescript-xmlobjects": "^1.1.4",
    "node-sass": "^4.9.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~6.0.0 || >=6.1.0",
    "tns-core-modules": "^4.1.1",
    "zone.js": "^0.8.26"
  }

Please tell us how to recreate the issue in as much detail as possible.

The best approach would be to get your code running in the NativeScript Playground and share the link with us, along with any additional details or steps to reproduce needed for examining the issue there.

This seems to be related to updating to 4.1.2 and my tsconfig file. Here is my ts.config.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": false,
        "noEmitOnError": false,
        "skipLibCheck": true,
        "lib": [
            "es6",
            "dom",
            "es2015.iterable"
        ],
        "baseUrl": ".",
        "paths": {
            "*": [
                "./node_modules/tns-core-modules/*",
                "./node_modules/*"
            ]
        }
    },
    "exclude": [
        "node_modules",
        "platforms"
    ]
}

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

This is the first thrown error line in my generated javascript:

var _1 = require(“.”);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
NickIlievcommented, Jul 30, 2018

@bradrice try to reset the application by deleting node_modules, platforms and hooks and then rebuilding again.

rm -rf node_modules platforms hooks
npm i
tns platform add android
tns run android
2reactions
bradricecommented, Aug 1, 2018

I finally got my app to boot up. For some reason on the last update to 4.1.2 nativescript for android seems to not like importing from barrels.

I had to change my code from:

import { LoggerService, MyHttpGetService, AnimationService, PlatformService } from '.';

to:

import { LoggerService} from './logger.service';
import { MyHttpGetService } from './http.service';
import { AnimationService } from './animation.service';
import  { PlatformService } from './platform.service';

The strange thing is it was working fine for ios, so the compilers work differently with regard to imports.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to find module: "nativescript-angular/http", relative to
That didn't help. It works in the emulator. I tried to use http-client instead but it wouldn't start. I've updated to the latest...
Read more >
Guild run can't find module/relative import - Troubleshooting
My code is calling a git command at execution. But guild is running the code from another (temporary) folder, which is not a...
Read more >
tns run android - NativeScript Docs
When running this command without passing --release flag, the HMR (Hot Module Replacement) is enabled by default. In case you want to disable...
Read more >
Configuring Module Resolution On Typescript and Jest
However trying to run the transpiled code fails throwing an error like. Error: Cannot find module '@/services/person' at Function.Module.
Read more >
Why TypeScript Paths Failed Me | Mitchell Simoens Blog
When importing files, relative paths could get ugly but with aliases they can be relative ... Error: Cannot find module '@/components/Foo'.
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