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.

Aliases in serverless-webpack are not supported

See original GitHub issue

This is a Bug Report

Description

Trying to resolve aliases through typescript and webpack with this configuration on the webpack side:

resolve: {
    alias: {
      '@/': path.resolve(__dirname, './src/'),
    },
  },

Whenever I use import syntax of import { test } from '@/folder/file' and try to build, it throws an error

Serverless: Invoke webpack:package
Serverless: Fetch dependency graph from ....examplePath/package.json
Serverless: WARNING: Could not determine version of module @/folder
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: @/folder, source-map-support@^0.5.19
 
  Error --------------------------------------------------
 
  yarn install --frozen-lockfile --non-interactive failed with code 1
  error An unexpected error occurred: "https://registry.yarnpkg.com/@%2fcommon: Not found".

I also have tsconfig set with these parameters:

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

Additional Data

  • Serverless-Webpack Version you’re using: 5.3.2
  • Webpack version you’re using: 4.43.0
  • Serverless Framework Version you’re using: 1.72.0
  • Operating System: macOS

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

2reactions
tafelnlcommented, Jun 15, 2020

I managed to get it to work fairly easily without problems. I am not using TypeScript however.

Anyway, my config:

  // webpack.config.js
  resolve: {
    alias: {
      '~': path.resolve(__dirname, 'src/'),
    },
  },
  // .eslintrc.js
  // need to run following command first:
  // npm i eslint-import-resolver-webpack --save-dev
  settings: {
    'import/resolver': 'webpack',
  },
1reaction
fernando-mfcommented, Jul 14, 2020

I think you are missing the extensions in webpack.resolve. I’m using typescript and aliases work fine. Here’s my config

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

// tsconfig.json
"baseUrl": "./src/",
"paths": {
    "@app/*": ["./*"]
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack resolve.alias does not work with typescript?
This solved my problem: we were using a custom module syntax which defined aliases to files other than index . Renaming the files...
Read more >
Webpack alias does not work in typescript file : WEB-29207
Sample projects. In src/main.ts there is two call hello.world() which is correct and hello.notWorld() which cause compile error.
Read more >
serverless-aws-alias-fixed
Serverless plugin to support AWS function aliases. Latest version: 2.0.1, last published: 2 years ago.
Read more >
Serverless with Webpack and TypeScript
If you're using the de facto plugin for TypeScript, Serverless Plugin TypeScript , then at least one feature it doesn't support is path...
Read more >
terraform-aws-modules/lambda/aws
Store deployment packages locally or in the S3 bucket. Support almost all features of Lambda resources (function, layer, alias, etc.) Lambda@ ...
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