Skip to content
New issue

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

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

Already on GitHub? # to your account

Support for tsconfig paths #150

Closed
odensc opened this issue Dec 12, 2018 · 6 comments
Closed

Support for tsconfig paths #150

odensc opened this issue Dec 12, 2018 · 6 comments
Labels
bug Something isn't working

Comments

@odensc
Copy link
Contributor

odensc commented Dec 12, 2018

In my tsconfig.json I use the paths option:

"compilerOptions": {
  [...]

  "paths": {
    "@*": ["./src/*"]
  },
}

Which allows me to import files as such:

import validateToken from "@auth/jwt"; // => <root>/src/auth/jwt.ts

However ncc's module resolution is incompatible with this feature, giving the following error:

ncc: Module directory "<dir>" attempted to require "@auth/jwt" but could not be resolved, assuming external.

Something like tsconfig-paths-webpack-plugin could be used to support this configuration.

I could submit a PR for this if there are no objections.

@rauchg
Copy link
Member

rauchg commented Dec 12, 2018

@odensc sounds like a good idea. I think ncc should support all the options of tsconfig.json predictably

@rauchg rauchg added the bug Something isn't working label Dec 12, 2018
@rauchg rauchg closed this as completed in 4c227fb Dec 16, 2018
guybedford added a commit that referenced this issue Dec 17, 2018
rauchg added a commit that referenced this issue Dec 17, 2018
rauchg added a commit that referenced this issue Dec 17, 2018
* Revert "fix minify default (#168)"

This reverts commit c289b28.

* Revert "Reduce asset emission and handle unexpected core assets (#166)"

This reverts commit b83e921.

* Revert "use graceful-fs (#167)"

This reverts commit 4ab1f82.

* Revert "fix ignore"

This reverts commit e6ab392.

* Revert "add typescript config for test"

This reverts commit fa95d0b.

* Revert "0.6.0"

This reverts commit 2f12e50.

* Revert "add typescript test"

This reverts commit d4d0ead.

* Revert "Add support for tsconfig `paths`. (fixes #150) (#151)"

This reverts commit 4c227fb.
rauchg added a commit that referenced this issue Dec 17, 2018
rauchg added a commit that referenced this issue Dec 17, 2018
@seawatts
Copy link

I am still getting the same error as @odensc

tsconfig.json

{
  "compilerOptions": {
    "outDir": "dist",
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "esnext",
    "lib": ["esnext"],
    "sourceMap": true,
    "baseUrl": ".",
    "rootDir": "./",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "suppressImplicitAnyIndexErrors": true,
    "esModuleInterop": true,
    "noUnusedLocals": false,
    "skipLibCheck": true,
    "noUnusedParameters": false,
    "declaration": true,
    "paths": {
      "@shuffl/*": ["src/*"]
    }
  },
  "exclude": ["node_modules", "dist"]
}

now.json

{
  "version": 2,
  "env": {
    "IS_NOW": "true"
  },
  "builds": [
    {
      "src": "./src/**/*.ts",
      "use": "@now/node@canary"
    }
  ],
  "routes": [
    { "src": "/(.*)", "dest": "/src/index" }
  ]
}

@odensc
Copy link
Contributor Author

odensc commented Feb 13, 2019

Hi @seawatts, if you could create a minimal repo that reproduces your issue that would be great. I can't seem to reproduce this with your basic tsconfig: https://gist.github.com/odensc/d52147afecfa697852171402cf5eb605

Perhaps it has something to do with now?

@liamdanielduffy
Copy link

Hi @odensc,

The reproduction for this issue is here:
https://github.com/liamdanielduffy/explorer-v2

I have a repo with roughly the following structure

+ api
--- + src
--- tsconfig.json

and the following lines in my tsconfig.json:

"paths": {
        "~/*": [
            "./api/src/*"
        ]
    }

Then I would like my import paths beginning with ~/for all my *.ts files in src/ to be resolved from src/.

With this setup, I'm able to successfully run now dev to serve my API locally.

However, when I deploy to now, I see the following output error when I send a GET request to any of my endpoints:

Cannot find module '~'
Did you forget to add it to "dependencies" in `package.json`?

@odensc
Copy link
Contributor Author

odensc commented May 7, 2019

Hey @liamdanielduffy,

Again, I cannot reproduce this with your example and ncc. The output JavaScript runs fine and the imports are translated properly. So I believe it's an issue with Now, considering @seawatts was also using Now.

Sorry I couldn't help.

@liamdanielduffy
Copy link

No worries, I’ll follow up in the now-builders repo!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants