Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces require to npm module #71

Closed
she11sh0cked opened this issue Dec 6, 2021 · 4 comments
Closed

Replaces require to npm module #71

she11sh0cked opened this issue Dec 6, 2021 · 4 comments

Comments

@she11sh0cked
Copy link

Given the following typescript file...

// file: src/index.ts

import graphql from "graphql";

import typeDefs from "./graphql/typeDefs";

export { graphql, typeDefs };

with the following tsconfig...

// file: tsconfig.json

{
    "compilerOptions": {
        "baseUrl": "./src",
        "paths": {
            "~/*": ["*"]
        }
    }
}

tsc-alias modifies the imports like so:

// file: src/index.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.typeDefs = exports.graphql = void 0;
//!!! orig: const graphql_1 = __importDefault(require("graphql"));
const graphql_1 = __importDefault(require("./graphql"));
exports.graphql = graphql_1.default;
const typeDefs_1 = __importDefault(require("./graphql/typeDefs"));
exports.typeDefs = typeDefs_1.default;
//# sourceMappingURL=index.js.map

I guess the require('graphql') is modified because there is a folder called "graphql" in src/ right? Is there a way to prevent paths to npm packages from being modified?

Here is a repo containing a jest test for this: https://github.com/she11sh0cked/tsc-alias-issue

@raouldeheer
Copy link
Contributor

This problem is because of issue #63
This shouldn't happen if the graphql directory doesn't have a index file.

@she11sh0cked
Copy link
Author

The graphql directory does in fact not have a index file.

@raouldeheer
Copy link
Contributor

pr #72 should add the functionality to disable the BaseUrl replacer with a simple tsconfig option.

{
  "compilerOptions": {
    ...
  },
  "tsc-alias": {
    "replacers": {
      "BaseUrl": {
        "enabled": false
      }
    }
  }
}

@searleser97
Copy link

I don't think just disabling baseUrl replacements would be a proper solution, that means we can't use it without defining path aliases right? Could we instead add an option to ignore some folders in the outDir ? in this particular case it would be the "graphql" folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants