Error: Declaration emit for this file requires using private name
See original GitHub issueHi, I’m not sure I used this packages correctly.
I create a subfolders from the project and then npm install package inside that folder with only packages I want.
Lastly, run npm-dts, but got a bunch of errors like error TS9005: Declaration emit for this file requires using private name 'LiveRegion'. An explicit type annotation may unblock declaration emit.
the directory structure:
subfolder
- package.json
- package-lock.json
- tsconfig.json
- node_modules
tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext",
"ES6"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": [
"node_modules/@chakra-ui/**/*"
],
"exclude": []
}
package.json
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"type-gen-wins": "%INIT_CWD%/node_modules/.bin/npm-dts -L debug --output index.d.ts generate",
"type-check": "tsc"
},
"dependencies": {
"@chakra-ui/react": "^1.7.1",
"@emotion/react": "^11.6.0",
"@emotion/styled": "^11.6.0",
"framer-motion": "^4.1.17"
},
"devDependencies": {
"npm-dts": "^1.3.10"
}
}
Sorry for dumping a lot of things, I know it’s not supported to be Stackoverflow.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Generating Type Definitions from Javascript is blocked by ...
and it was throwing this error: error TS9005: Declaration emit for this file requires using private name 'exports'. An explicit type annotation ...
Read more >Declaration will not emit due to private name usage
I want to be able to use this TypesScript project from a normal JavaScript project, so my understanding is that I need to...
Read more >Vue 'watch' problem: Declaration emit for this file requires ...
Coding example for the question Vue 'watch' problem: Declaration emit for this file requires using private name 'handler'. An explicit type annotation may ......
Read more >TypeScript errors and how to fix them
Only public and protected can be used. To solve the problem, the private keyword must be removed from the name property of the...
Read more >Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and ... error! A type-only import can specify a default import or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am not entirely sure but it seems as if you are attempting to generate typings for another module inside node_modules. Normally that module should bring its own typings together with compiled JavaScript files OR it should provide plain TypeScript sources. In this case it seems that @chakra-ui provides TypeScript files so you should be able to import them directly in some TypeScript project and build them together with your project’s source.
If your project is JavaScript-based you might in fact need to compile that library first. If you just build it using TSC it should generate a JavaScript file next to each TypeScript file and that should allow you to consume it.
npm-dts would be used if you were a developer of @chakra-ui and you would want to publish a pre-built minimized version of the library without original source code. In such case ideally @chakra-ui project would import npm-dts or npm-dts-webpack-plugin and use it to produce index.d.ts which could then be used for type suggestions.
Now, even though I do not think you needed npm-dts for your use case, let’s see what is happening. If your sub-folder only contains those 4 files - I don’t think that npm-dts would work at all. By default it is looking for index.ts entry file in the root folder which is by default current working directory (same as package.json path). Hence I would expect npm-dts to not be able to find it at all and fail (though error message seems a bit weird). Entry file name and root folder name can be changed manually using –entry and –root. You do not need to specify output in your case because it is “index.d.ts” by default. But having said that - I am not sure what purpose it would serve and what problem you are trying to solve.
Hope it gives some thoughts.
Late to the party here, but I solved this for a similar by adding a JSDoc
@typecomment above the offending thing. In my case I had a class that had a getter which returned a different class and any usage of the getter would give this error.So this…
Is fixed by this…