linode / manager

Akamai's Cloud Manager is an open-source, single-page application designed as the primary frontend interface for interacting with the Linode API. It is entrusted by hundreds of thousands of customers with the management of their Linode services.

Home Page:https://cloud.linode.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compilation error when including @linode/api-v4 as a dependency

elmerbulthuis opened this issue · comments

when compiling with typescript we get the following error

node_modules/@linode/api-v4/lib/support/types.d.ts:1:24 - error TS2307: Cannot find module 'src/account/types' or its corresponding type declarations.

1 import { Entity } from 'src/account/types';
                         ~~~~~~~~~~~~~~~~~~~

workaround:

in a file called global.d.ts:

declare module "src/account/types" {
    export interface Entity {
    }
}

but this is not ideal!

Can you provide some more information on how to reproduce this?

sure!

first setup a typescript project..

install linode sdk

 npm install @linode/api-v4@0.53.2

then create a file with this concent:

import * as linodeApi from "@linode/api-v4";

let linode: linodeApi.Linode;

compile and there is the error!

I'm unable to replicate any error! Maybe this could be a tsconfig.json related?

commented

@bnussman Here is an example project that illustrates the problem: https://github.com/Gameye/reproduce-linode-issue

Perhaps I should also note:

$ npm version
{
  npm: '7.4.3',
  node: '15.7.0',
  v8: '8.6.395.17-node.23',
  uv: '1.40.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.17.1',
  modules: '88',
  nghttp2: '1.42.0',
  napi: '7',
  llhttp: '2.1.3',
  openssl: '1.1.1i',
  cldr: '38.1',
  icu: '68.2',
  tz: '2020d',
  unicode: '13.0'
}

I'm not completely sure of the root cause, but I was able to get your Typescript compiler to run by adding "skipLibCheck": true into your tsconfig.json.

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./node",
    "rootDir": "./src",
    "importHelpers": true,
    "strict": true,
    "skipLibCheck": true
  },
  "include": [
    "src/**/*"
  ]
}

Let me know if this this is enough for you to get up and running! If not, let me know so I can look more into it! Thanks!

commented

I'm not completely sure of the root cause, but I was able to get your Typescript compiler to run by adding "skipLibCheck": true into your tsconfig.json.

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./node",
    "rootDir": "./src",
    "importHelpers": true,
    "strict": true,
    "skipLibCheck": true
  },
  "include": [
    "src/**/*"
  ]
}

Let me know if this this is enough for you to get up and running! If not, let me know so I can look more into it! Thanks!

@elmerbulthuis's temporary workaround works as well but it is not actually fixing the problem. The point of using TypeScript is to make sure that everything is checked!

If you look at all the other imports throughout the source code, you can see that no other import points from the source root. So one solution would be to change:

import { Entity } from 'src/account/types';

to:

import { Entity } from '../account/types';

And I could make a PR for that. However, I don't know why it even starts with src in the first place. Is this an actual bug or was this done on purpose? This issue seems to have existed throughout quite a lot of versions of the SDK so if it really is a bug, I'd find it odd that no one else has detected-and reported it.

I think we use paths that start with src/ by design. I'll keep looking into this...