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

TypeScript compilation errors #1862

Closed
unstubbable opened this issue Jan 11, 2018 · 9 comments · Fixed by #1864
Closed

TypeScript compilation errors #1862

unstubbable opened this issue Jan 11, 2018 · 9 comments · Fixed by #1864

Comments

@unstubbable
Copy link
Contributor

First of all, thanks a lot for the effort that went into #1806! ❤️

Unfortunately this broke integration of Rollup into other TypeScript projects. These are the compiler errors I'm seeing in a minimal example project:

node_modules/rollup/dist/typings/Module.d.ts(1,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/Module.d.ts(5,30): error TS2307: Cannot find module 'source-map'.
node_modules/rollup/dist/typings/Module.d.ts(84,9): error TS2411: Property ''*'' of type 'NamespaceVariable | undefined' is not assignable to string index type 'Variable'.
node_modules/rollup/dist/typings/ast/nodes/BlockStatement.d.ts(3,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/ClassDeclaration.d.ts(4,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/ExportDefaultDeclaration.d.ts(5,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/FunctionDeclaration.d.ts(3,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/Identifier.d.ts(6,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/Property.d.ts(5,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/TemplateLiteral.d.ts(2,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/shared/Node.d.ts(4,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/ast/nodes/shared/Statement.d.ts(2,25): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/node-entry.d.ts(5,36): error TS2307: Cannot find module 'package.json'.
node_modules/rollup/dist/typings/rollup/index.d.ts(3,30): error TS2307: Cannot find module 'source-map'.
node_modules/rollup/dist/typings/rollup/index.d.ts(5,27): error TS2307: Cannot find module 'magic-string'.
node_modules/rollup/dist/typings/rollup/index.d.ts(18,69): error TS2304: Cannot find name 'Node'.
node_modules/rollup/dist/typings/utils/mergeOptions.d.ts(1,32): error TS2307: Cannot find module '../../src/rollup/index'.
node_modules/rollup/dist/typings/watch/index.d.ts(2,30): error TS2307: Cannot find module 'chokidar'.
@unstubbable
Copy link
Contributor Author

unstubbable commented Jan 11, 2018

Obviously the Cannot find module errors could be prevented by a consuming project by installing typings from @types. They are only available for source-map and chokidar though, not for magic-string. Also, Cannot find name 'Node' can be resolved by adding the dom lib in the compiler options. So the remaining issues are:

node_modules/rollup/dist/typings/Module.d.ts(84,9): error TS2411: Property ''*'' of type 'NamespaceVariable | undefined' is not assignable to string index type 'Variable'.
node_modules/rollup/dist/typings/node-entry.d.ts(5,36): error TS2307: Cannot find module 'package.json'.
node_modules/rollup/dist/typings/utils/mergeOptions.d.ts(1,32): error TS2307: Cannot find module '../../src/rollup/index'.

and several occurrences of Cannot find module 'magic-string'.

@unstubbable
Copy link
Contributor Author

unstubbable commented Jan 11, 2018

I'm wondering whether @types/source-map and @types/chokidar should be listed as dependencies?

@guybedford
Copy link
Contributor

guybedford commented Jan 11, 2018 via email

@unstubbable
Copy link
Contributor Author

unstubbable commented Jan 11, 2018 via email

unstubbable added a commit to unstubbable/rollup that referenced this issue Jan 11, 2018
fixes rollup#1862

To fix all compiler errors mentioned in rollup#1862 a TypeScript
project that imports Rollup needs to add theses devDependencies:

- @types/chokidar
- @types/source-map
- magic-string
@lukastaegert
Copy link
Member

Also, Cannot find name 'Node' can be resolved by adding the dom lib in the compiler options

Unfortunately this is most probably the wrong Node; the right one is https://github.com/rollup/rollup/blob/master/src/ast/nodes/shared/Node.ts.

Will take a look at #1864 later. As for @guybedford's comment: When we did the conversion earlier, we never considered the types to be used publicly as this was not the problem we were trying to solve. Thus the few types that actually make sense to be used publicly are far too generic. See my comment here: #1837 (comment)

But I see the advantages of maintaining these option types in rollup itself as for TypeScript users, deprecations etc. will always be up to date with the rollup version they actually use.

Unfortunately I do not see I will find the time to wrap my head around improving this any time soon but if someone from the community feels up to this, please let me know! I will certainly try to support you with this!

also cc @alan-agius4

@alan-agius4
Copy link
Contributor

alan-agius4 commented Jan 12, 2018

I think those who are having error might not have skipLibCheck: true flag in tsconfig.json

I'll try to look at this soon. And will also review #1864

Gimma a couple of hours and will get back with more info :-)

@alan-agius4
Copy link
Contributor

The main problem with magic-string and source-map is that rollup inlines the libraries and are not marked as dependencies.

@unstubbable
Copy link
Contributor Author

The main problem with magic-string and source-map is that rollup inlines the libraries and are not marked as dependencies.

Yes, that is unfortunate (for this scenario) and means you have to manually install @types/source-map, magic-string and also @types/chokidar as devDependency as mentioned in #1864. At least I'm not aware of another fix.

@alan-agius4
Copy link
Contributor

alan-agius4 commented Jan 12, 2018

@KingHenne just a small correction you don't need to install @types/source-map. This is a stub and one should install the actual source-map library.

So for TS users without skipLibCheck you'd need to install

npm install @types/chokidar source-map magic-string --only=dev

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

Successfully merging a pull request may close this issue.

4 participants