serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

User defined path shortcuts defined in tsconfig.json are not resolved in transpiled code

Open mstn opened this issue 5 years ago • 9 comments

Hi there!

I am using shortcut paths in my tsconfig.json file. For example:

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

Paths are not expanded/resolved in transpiled code. This is a known feature/bug of Typescript https://github.com/microsoft/TypeScript/issues/26722

There are a few workarounds as discussed in the issue above. One suggestion is to resolve the problem at the level of the output bundler (e.g. webpack and, in our case, this plugin).

I was just wondering if this plugin could resolve shortcuts before/after transpiling the code.

thanks

mstn avatar Oct 23 '19 14:10 mstn

please add this!

marcosfede avatar Nov 05 '19 17:11 marcosfede

Any news on adding this feature? Thanks :)

juank11memphis avatar Feb 14 '20 17:02 juank11memphis

Here's a quick fork off v1.1.7 to resolve this

npm install @theslyone/[email protected].

It's somewhat of a hack but works, ensure .serverless and .build directories are deleted before running

theslyone avatar May 15 '20 23:05 theslyone

any news on this issue?

maazmk avatar Jul 27 '20 06:07 maazmk

Same issue with baseUrl. My absolute imports won't work. For now I'll switch to relative imports because it's a small project. But would be nice to have something more robust here.

ThomasLabstep avatar Oct 08 '20 07:10 ThomasLabstep

If you are using serverless-webpack (installed by default if you used sls create --template aws-nodejs-typescript)

In your webpack.config.js

// webpack.config.js
resolve: {
  extensions: ['.ts'],
  alias: {
    '@app': path.resolve(__dirname, './src'),
  },
},

// tsconfig.json
"baseUrl": "./src/",
"paths": {
    "@app/*": ["./*"]
},

Found in this thread

brothatru avatar Nov 01 '20 02:11 brothatru

Will this feature be implemented?

jsefiani avatar May 25 '21 17:05 jsefiani

Sent a PR implementing this is #241 ... but like my other PRs to this repo, there is no sign of it ever getting merged in...

perrin4869 avatar Jul 08 '21 19:07 perrin4869

Would be super useful to have this! +1

jasiene avatar Oct 21 '21 22:10 jasiene