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
Fix: declare var require: NodeRequire #7049
Conversation
tsc reports an error that the require variable should be of type NodeRequire and not Require. Works with this fix.
requirejs/require.d.ts to author (@jbaldwin). Could you review this PR? Checklist
|
Hope this gets merged soon |
+1 for the merge :) |
Any news about this one? |
Jumping in on this one as well. |
|
Any status on the PR? I know it's very minor but I don't have "rights" to merge it right now. I'm guessing the build failed because there is some dependency on Node? For anyone wondering how to quick fix it. Just change
|
@larsw please fix travis ci failed and resolve conflict. |
Thanks for your contribution. This PR has failing CI tests and can not be merged in at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to merge this code in, please open a new PR that has been merged and rebased with the |
Can please make someone a suggestion how to solve this? If someone includes node and require they seem to clash. This is soo annoying. |
I "fixed" this by modifying the .d.ts files for Node and RequireJS:
This needs to be done in both .d.ts files, so one PR with this fix will not fix the error. Ideas? |
- run "npm update" - clean package.json - switch deprecated packages to non-deprecated ones - mainly switch from "tsd" to "typings" NOTE: node.d.ts and require.d.ts have been manually edited to prevent Require and NodeRequire from clashing (see e.g. DefinitelyTyped/DefinitelyTyped#7049 (comment)) - replace "throw err; return null;" with "return Promise.reject(err)", as typescript and throwing does not work together (see e.g. microsoft/TypeScript#7588) - fix some other typing stuff - fix 'use strict';s to be on top of the files Please run "rm -r node_modules; npm install" after getting this commit.
- run "npm update" - clean package.json - switch deprecated packages to non-deprecated ones - mainly switch from "tsd" to "typings" NOTE: node.d.ts and require.d.ts have been manually edited to prevent Require and NodeRequire from clashing (see e.g. DefinitelyTyped/DefinitelyTyped#7049 (comment)) - replace "throw err; return null;" with "return Promise.reject(err)", as typescript and throwing does not work together (see e.g. microsoft/TypeScript#7588) - fix some other typing stuff - fix 'use strict';s to be on top of the files Please run "rm -r node_modules; npm install" after getting this commit.
+1 |
This issue is related with the next errors: ERROR in node_modules/@types/webpack-env/index.d.ts
(183,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'RequireFunction'.
ERROR in node_modules/@types/webpack-env/index.d.ts
(232,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'module' must be of type 'NodeModule', but here has type 'Module'.
ERROR in ./autoload.ts
(8,21): error TS2339: Property 'context' does not exist on type 'NodeRequire'. Problem come when you try use this types:
Any one know a provional fix? |
@pablorsk I ran into a similar error I long time ago. It was for |
@Nocomm The issue still happens with |
No. The error @pablorsk was seeing was the exact same error I saw for a |
@Dachizy okay. I had the same issue. But I did something different to resolve this. I went to source of requirejs.d.ts in |
I solve the problem by deleting the /node_module and |
Hi Guys, Thanks for posting this information, it helped me produce a solution that does not involve changing type definitions from npm/typings, but rather allows us to merge interfaces and allow NodeRequire to accept I have not played with requirejs, or node type definitions. Replace your require definition with an interface, as TS will Auto merge them for us. // Allow typescript to import css files (and other media)
interface NodeRequire {
<T>(path: string): T;
(paths: string[], callback: (...modules: any[]) => void): void;
ensure: (paths: string[], callback: (require: <T>(path: string) => T) => void) => void;
} If this is fundamentally wrong, please tell me why, as I am fairly new to TS. Hope it can help others. reference: https://www.typescriptlang.org/docs/handbook/declaration-merging.html |
Maybe we need start again with new version of We use If you have the same problem, please, share your includes @types. (try with remove and reinstal node_modules fisrt) |
I may have something else going on, but I am using node ^7.0.18 - see package.json below for versions of my included types
|
tsc reports an error that the require variable should be of type NodeRequire and not Require.
Works with this fix.