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

nodenext: Module '"docx"' has no exported member 'Paragraph'. #2635

Open
Spitzbua opened this issue Mar 11, 2024 · 2 comments
Open

nodenext: Module '"docx"' has no exported member 'Paragraph'. #2635

Spitzbua opened this issue Mar 11, 2024 · 2 comments

Comments

@Spitzbua
Copy link

Cannot import any other Types but document using Basic Usage Example

import { Document, Packer, Paragraph, TextRun } from "docx";

leads to following error: Module '"docx"' has no exported member 'Paragraph'

I tried several import variants, but none of them was working:
#1201, #2365

Is it a misconfiguration or an library issue? Any help appreciated!

Options:

{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"noImplicitReturns": true,
"noUnusedLocals": false,
"skipLibCheck": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es6",
"typeRoots": [
"./node_modules/@types",
"./types"
]
},
"compileOnSave": true,
"include": [
"src"
]
}

@OperationsOfficerPRMG
Copy link

I'm also experiencing this, is anyone able to please help?

I was able to use this module in pure JS but when switching to TS it won't compile and gives many errors which look like this:

Property 'Packer' does not exist on type 'typeof import("./node_modules/docx/build/index", { with: { "resolution-mode": "import" } })'.

The compiler will only seem to accept something like the following (non-sensical) code.

const { Document } = docx;
const { Packer, Paragraph, Table, TableCell, TableRow, Header, HeadingLevel, Footer, LevelFormat, TextRun, WidthType, AlignmentType, VerticalAlign, convertMillimetersToTwip, TableBorders, ShadingType, BorderStyle, ImageRun, HorizontalPositionAlign, VerticalPositionAlign, TextWrappingType, UnderlineType, FrameAnchorType } = Document;

Which gives errors like

TypeError: convertMillimetersToTwip is not a function

Here's my tsconfig,json

{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 21",
"_version": "21.0.0",
"files": [
"index.mts",
"index.d.ts"
],
"compilerOptions": {
"lib": [
"es2023",
"es5",
"es6",
"dom",
"dom.iterable"
],
"module": "node16",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node16"
}
}

@tothdanielax
Copy link

Same here, even if it seems to work in local context.

import { IPatch, PatchType, TextRun, patchDocument } from 'docx';

TS could not infer any of these types, tsc tells this:
> error TS2305: Module '"docx"' has no exported member 'patchDocument'.

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

3 participants