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

Path/baseUrl creates broken Type Definitions #21507

Closed
dolanmiu opened this issue Jan 31, 2018 · 4 comments
Closed

Path/baseUrl creates broken Type Definitions #21507

dolanmiu opened this issue Jan 31, 2018 · 4 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@dolanmiu
Copy link

dolanmiu commented Jan 31, 2018

TypeScript Version: 2.6.2

Search Terms: npm, link, declarations, type definitions, awesome-typescript-loader, paths, baseUrl

I have tried to search for this, but couldn't find something similar, so I am asking 😄.

I am using awesome-typescript-loader to bundle my typescript project into one build/index.js file:
https://github.com/dolanmiu/docx/blob/master/webpack.config.js#L7-L8

I am using compilerOptions.paths to enable me to import from root:
https://github.com/dolanmiu/docx/blob/master/tsconfig.json#L14-L18

I also have declarations: true:
https://github.com/dolanmiu/docx/blob/master/tsconfig.json#L11

However, when I npm link, and use the library, I get the following error:

  • Notice how it is complainig about the root imports, such as file/media
  • packer is an interface
../../docx/build/export/index.d.ts(3,15): error TS2307: Cannot find module './packer/packer'.
../../docx/build/export/packer/express.d.ts(3,22): error TS2307: Cannot find module 'file'.
../../docx/build/export/packer/express.d.ts(4,25): error TS2307: Cannot find module './packer'.
../../docx/build/export/packer/local.d.ts(2,25): error TS2307: Cannot find module './packer'.
../../docx/build/file/document/body/section-properties/columns/columns-attributes.d.ts(1,39): error TS2307: Cannot find module 'file/xml-components'.
../../docx/build/file/document/body/section-properties/doc-grid/doc-grid-attributes.d.ts(1,39): error TS2307: Cannot find module 'file/xml-components'.
../../docx/build/file/document/body/section-properties/page-margin/page-margin-attributes.d.ts(1,39): error TS2307: Cannot find module 'file/xml-components'.
../../docx/build/file/document/body/section-properties/page-size/page-size-attributes.d.ts(1,39): error TS2307: Cannot find module 'file/xml-components'.
../../docx/build/file/document/body/section-properties/section-properties.d.ts(1,30): error TS2307: Cannot find module 'file/xml-components'.
../../docx/build/file/document/document.d.ts(1,28): error TS2307: Cannot find module 'file/media'.
../../docx/build/file/document/document.d.ts(2,30): error TS2307: Cannot find module 'file/xml-components'.

image

Expected behavior: Create typescript definitions without red underline errors

Actual behavior: Red underline errors, and error log

Related Issues:

#6496

Project:

https://github.com/dolanmiu/docx

@dolanmiu dolanmiu changed the title Path/baseUrl creates broken type definitions Path/baseUrl creates broken Type Definitions Jan 31, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jan 31, 2018

I am not sure i understand the intention behind your paths. if all what you want to say is resolve file/media to ./src/file/media/index, then you all you need is the baseUrl and remove paths.

I tried running tsc on the tsconfig.json you provided in docx, and i got no module related errors.. i am guessing this is a loader issue. i would recommend you filing it on https://github.com/s-panferov/awesome-typescript-loader/issues instead.

@mhegazy mhegazy added the External Relates to another program, environment, or user action which we cannot control. label Jan 31, 2018
@dolanmiu
Copy link
Author

I have the same issue when removing paths and only keeping the baseUrl

I have tried tsc, and yes, you are right, it does compile with no errors, but when I try running a demo or using the library, I get the error:

Error: Cannot find module 'file/xml-components'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Dolan\Documents\docx\build\file\paragraph\formatting\alignment.js:3:26)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

This makes sense as alignment.js has:

const xml_components_1 = require("file/xml-components");

Obviously it won't be able to find require("file/xml-components"), cos its specific to the library

@mhegazy
Copy link
Contributor

mhegazy commented Jan 31, 2018

The compiler will not change your file path/import module name. what baseUrl tells the compiler is that at runtime all modules will be copied to this folder. AMD modules are usually distributed this way. if this is not your setup, do not use baseUrl/paths.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants