Skip to content

module ... was resolved to '...', but '--allowJs' is not set error for explicit node_module import #15970

@justinfagnani

Description

@justinfagnani

TypeScript Version: 2.3.2

Code

Project layout:

|__node_modules/
|  |__foo/
|     |__foo.js
|__src/
   |__index.ts

tsonfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "lib",
    "rootDir": "src",
    "target": "esnext"
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx"   
  ], "exclude": [
    "node_modules/**/*",
    "third_party/**/*"
  ]
}

index.ts:

import * from '../node_modules/foo/foo.js';

Expected behavior:

Compilation works

Actual behavior:

error TS6059: File '/Users/justin/Documents/Projects/test/node_modules/foo/foo.js' is not under 'rootDir' '/Users/justin/Documents/Projects/test/src'. 'rootDir' is expected to contain all source files.
error

My lib/ directory, which should contain just the compiled contents of src/ contains src/ and node_modules/ subdirectories.

If I remove allowJs, then tsc complains that I'm importing JS and need to add the option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions