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

NG4 build error on import #1054

Closed
Phivan opened this issue Oct 9, 2017 · 12 comments
Closed

NG4 build error on import #1054

Phivan opened this issue Oct 9, 2017 · 12 comments

Comments

@Phivan
Copy link

Phivan commented Oct 9, 2017

Flatpickr version :3.1.3"
node : v8.6.0
npm: 5.3.0
ngcli: 1.3.2

When I build my Angular 4 app using :

ng build --extract-css --progress --output-path ../public/ui

I get these errors :

ERROR in
my/path/ui/node_modules/flatpickr/src/types/options.ts (2,25): Cannot find module 'utils/dates'.
ERROR in
my/path/ui/node_modules/flatpickr/src/types/instance.ts (4,48): Cannot find module 'utils/formatting'.

It come from these lines

import { getWeek } from "utils/dates";
import { RevFormat, Formats, TokenRegex } from "utils/formatting";

I think that the problem is paths are wrong. Am I wrong ?

@chmln
Copy link
Member

chmln commented Oct 9, 2017

Hello,

How are you importing flatpickr?
If you're importing from the dist folder, the node module itself shouldn't be typechecked.

I'll see if including tsconfig.json will fix the errors.

@chmln
Copy link
Member

chmln commented Oct 9, 2017

I've included tsconfig.json in v3.1.4.
Please check if the issue persists.

Thank you.

@Phivan
Copy link
Author

Phivan commented Oct 9, 2017

I've just update to 3.1.4 but it does not work.
I'm importing flatpickr by using :
import * as flatpickr from 'flatpickr';

I've found a workaround by reading : https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Module%20Resolution.md

I've added
"flatpickr": [ "../node_modules/flatpickr/dist/flatpickr.min.js" ]

into tsconfig.app.json in 'paths' property.
But it does not seems to be a great solution

@antur84
Copy link

antur84 commented Oct 10, 2017

I have the same issue, I've just updated and we're running Angular CLI (which internally uses webpack), using the latest typescript version (2.5.3) and we're importing like:

import flatpickr from 'flatpickr';

and during build we get

ERROR in C:/Users/andre/Source/ui-guidelines/node_modules/flatpickr/src/types/instance.ts (4,48): Cannot find module 'utils/formatting'.
ERROR in C:/Users/andre/Source/ui-guidelines/node_modules/flatpickr/src/types/options.ts (2,25): Cannot find module 'utils/dates'.

I do get the same errors when building with a "normal" webpack build, not using Angular CLI.

VSCode also gives the same warnings if I open the files in question.

@chmln
Copy link
Member

chmln commented Oct 10, 2017

@Phivan those paths are based on the baseUrl option in the tsconfig, and looks like typescript does not take it into consideration.

I'll see what can be done.

@antur84
Copy link

antur84 commented Oct 10, 2017 via email

@dtaalbers
Copy link

Same here, getting the same errors on build. Looking forward to see this fixed.

@grzegorztomasiak
Copy link

grzegorztomasiak commented Oct 12, 2017

Same problem here, previous version was working fine. After the upgrade the error occurred.

ERROR in D:\Development\myproject\node_modules\flatpickr\src\types\options.ts
(2,25): error TS2307: Cannot find module 'utils/dates'.

ERROR in D:\Development\myproject\node_modules\flatpickr\src\types\instance.ts
(4,48): error TS2307: Cannot find module 'utils/formatting'.

ERROR in D:\Development\myproject\app\Resources\app\Common\Components\DatePicker\DatePicker.Component.vue.ts
(21,23): error TS2304: Cannot find name 'Flatpickr'.

ERROR in D:\Development\myproject\app\Resources\app\Common\Components\DatePicker\DatePicker.Component.vue.ts
(35,26): error TS2350: Only a void function can be called with the 'new' keyword.

The last version that works for me fine is 3.0.7. Everything above throws the given error.

@vince-koch
Copy link

@chmln I believe this can be resolved by using imports relative to the file rather than relative to the baseUrl configuration option. For example in "types/options.ts"
import { getWeek } from "utils/dates";
would change to
import { getWeek } from "./../utils/dates";

@chmln
Copy link
Member

chmln commented Oct 12, 2017

@vince-koch indeed, it can be resolved that way. But it is not a solution, it is a workaround.

I will see if typescript folks can do something about this.
If not, I will switch to relative paths for the next release.

Please use the workaround posted by @Phivan meanwhile.
Thank you all for your patience.

@marcusvy
Copy link

@chmln and @Phivan.
I solved the problem by changing the import lines to correct relative paths of file. For example in "flatpickr/src/plugins/confirmDate/confirmDate.ts"
import { Instance } from "types/instance";
was changed to
import { Instance } from "../../types/instance";

the same for other errors like "flatpickr/src/plugins/weekSelect/weekSelect.ts"
import { Instance, DayElement } from "types/instance";
whas change to
import { Instance, DayElement } from "../../types/instance";

@chmln chmln closed this as completed in 366fd33 Oct 14, 2017
@Amirastemp
Copy link

i have the same error any one has a solution :Error: node_modules/flatpickr/src/types/instance.ts:4:48 - error TS2307: Cannot find module 'utils/formatting' or its corresponding type declarations.

4 import { RevFormat, Formats, TokenRegex } from "utils/formatting";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants