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

CodeBlockWriter is not a constructor in v17.0.0 #1357

Closed
SferaDev opened this issue Nov 21, 2022 · 3 comments · Fixed by #1358
Closed

CodeBlockWriter is not a constructor in v17.0.0 #1357

SferaDev opened this issue Nov 21, 2022 · 3 comments · Fixed by #1358
Labels

Comments

@SferaDev
Copy link

Describe the bug

Version: 17.0.0

After upgrading to v17 I began receiving the following error when our tests attempted to run ts-morph:

TypeError: CodeBlockWriter is not a constructor
 ❯ ProjectContext.createWriter packages/codegen/node_modules/ts-morph/dist/ts-morph.js:20007:16
    20005|     createWriter() {
    20006|         const indentationText = this.manipulationSettings.getIndentati…
    20007|         return new CodeBlockWriter({
       |                ^
    20008|             newLine: this.manipulationSettings.getNewLineKindAsString(…
    20009|             indentNumberOfSpaces: indentationText === exports.Indentat…
 ❯ SourceFile._getWriter packages/codegen/node_modules/ts-morph/dist/ts-morph.js:3987:30
 ❯ SourceFile._getWriterWithChildIndentation packages/codegen/node_modules/ts-morph/dist/ts-morph.js:3969:29
 ❯ getNewText packages/codegen/node_modules/ts-morph/dist/ts-morph.js:2489:31
 ❯ insertIntoBracesOrSourceFile packages/codegen/node_modules/ts-morph/dist/ts-morph.js:2481:21
 ❯ insertIntoBracesOrSourceFileWithGetChildren packages/codegen/node_modules/ts-morph/dist/ts-morph.js:2513:5
 ❯ SourceFile._insertChildren packages/codegen/node_modules/ts-morph/dist/ts-morph.js:11468:20
 ❯ SourceFile.insertImportDeclarations packages/codegen/node_modules/ts-morph/dist/ts-morph.js:9161:25
 ❯ SourceFile.addImportDeclarations packages/codegen/node_modules/ts-morph/dist/ts-morph.js:9140:25
 ❯ SourceFile.addImportDeclaration packages/codegen/node_modules/ts-morph/dist/ts-morph.js:9

To Reproduce

Need to investigate further, opening for awareness.

@zivarah
Copy link

zivarah commented Nov 21, 2022

I'm also running into this. It looks like this line in the distributed ts-morph.js file:

var CodeBlockWriter = require('code-block-writer');

Is returning an object with a default property, but the ts-morph code is expecting the class to be returned directly:

CodeBlockWriter
{default: ƒ, __esModule: true}
default:
class CodeBlockWriter
__esModule:
true
[[Prototype]]:
Object

This feels very related to esModuleInterop, but unsure if that's actually in play here or not.

@dsherret
Copy link
Owner

dsherret commented Nov 21, 2022

That's weird. It should have compiled with esModuleInterop, but it seems like the output doesn't have that and I believe my tests didn't catch it because they're run through ts-node. I'll look into this right away.

Edit: Caused by the upgrade of rollup from v2 to v3.3

@dsherret
Copy link
Owner

Sorry about that. Should be fixed in 17.0.1 by reverting rollup from v3 to v2

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

Successfully merging a pull request may close this issue.

3 participants