I'm this problem on windows 10. I have a linked node_module that was created using npm link @pocesar/moip2, Typescript@next is trying to use the typings in the linked node_modules\@types\bluebird\index.d.ts
TypeScript Version: nightly
The tsc --listFiles shows:
../node-moip2/node_modules/@types/bluebird/index.d.ts(759,5): error TS2300: Duplicate identifier 'export='.
g:/www/neuro/node_modules/typescript/lib/lib.d.ts
g:/www/neuro/node_modules/@types/node/index.d.ts
g:/www/neuro/node_modules/@types/express-serve-static-core/index.d.ts
g:/www/neuro/node_modules/@types/mime/index.d.ts
g:/www/neuro/node_modules/@types/serve-static/index.d.ts
g:/www/neuro/node_modules/@types/express/index.d.ts
g:/www/neuro/node_modules/@types/body-parser/index.d.ts
g:/www/neuro/node_modules/@types/lodash/index.d.ts
g:/www/neuro/node_modules/@types/lru-cache/index.d.ts
g:/www/neuro/node_modules/@types/bluebird/index.d.ts
g:/www/neuro/src/server/modules/correios.ts
g:/www/node-moip2/node_modules/@types/bluebird/index.d.ts
g:/www/node-moip2/moip.d.ts
My local tsconfig.json is:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"inlineSourceMap": true,
"outDir": "lib",
"noImplicitReturns": true,
"noImplicitUseStrict": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": false,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"noUnusedParameters": true,
"pretty": true,
"newLine": "LF",
"allowJs": false,
"moduleResolution": "node",
"target": "es5",
"declaration": false
},
"rootDir": "src/server",
"exclude": [
"lib",
"src/user",
"src/client",
"src/buy",
"src/admin",
"data",
"config",
".vscode",
".tscache",
"node_modules",
"tests",
"conf",
"keys",
".sass-cache",
"views",
"public"
]
}
The tsconfig.json in moip2:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": false,
"outDir": ".",
"moduleResolution": "node",
"target": "es2015",
"declaration": true
},
"files": [
"moip.ts"
]
}
Do I need to use excludes? Doesn't files and excludes cancel each other?
Expected behavior:
Should ignore the node_modules on linked packages as well
Actual behavior:
The exclude option is being ignored for npm link'd packages
looks like we need to get real path when enumerating the types directories.
This is also an issue on OSX. The @types folders from within the _linked libraries_ are included when compiling the top-level package:
node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
../my-library/node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
I use my own gulp-npmworkspace to manage large projects and this is a show-stopper for me. Currently, the only workaround is to use physical paths in the package.json and call npm install every time you make a change.
Same root cause as #9771; the path machinery as it stands is fine as long as we don't freak out over importing two files with the same UMD global
Hmm, I'm not so sure the path machinery is fine actually.With this tsconfig.json
{
"compilerOptions": {
"jsx": "preserve",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"outDir": ".tmp",
"allowJs": true,
"rootDir": "."
},
"exclude": [
"node_modules",
"gulpfile.js"
]
}
I get these errors
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/common.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/config.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/config/cli-config.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/config/npm-config.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/config/syslog-config.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/container.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/exception.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/logger.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/transports.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/rasmus/Development/beanloop/shujin/node_modules/winston/lib/winston/transports/transport.js' is not under 'rootDir' '/home/rasmus/Development/beanloop/socialview/data'. 'rootDir' is expected to contain all source files.
shujin is an npm linked dependency and for some reason typescript uses its modules even though node_modules is excluded.
Should I open a new issue?
I'm still getting this problem with a node_module that has been linked to the project and has a @types. it's breaking "typings" from my typings directory (bunch of duplicate exports)
I think this is going to be fixed in 2.0.1, but that hasn't been released yet?
I'm using typescript@next (aka 2.1.0)
You're right @pocesar, I can't get it working either. I'm switching back to using DefinitelyTyped directly. No matter how I try to organise my packages, it doesn't work when I have a dependency symlinked. It still brings in the shared @types/xxx from the dependency and I get the duplicates.
This bug still exists on tsc version 2.0.3. it should be reopened.
@RyanCavanaugh this bug still exists for @types sub-submodules in a npm link dependency (as per @pocesar )
it happens when your npm link dependency re-exports definitions found in @types.
for example, in my new version of xlib I do export import lodash = require("lodash");
that works fine when I npm install xlib@next but when i then npm link xlib then I get those same Duplicate identifier 'export=' errors.
the same issue occurs if you have a relative link, such as: import xlib = require("../../xlib");
this is a regression from typescript 1.x, where you could have relative links no problem.
Same issue here. Seems like tsc also doesn't respect "typeRoots" in tsconfig.json. Still looks for types outsides of the folders listed there.
@jpzwarte this is a closed issue, marked as "fixed". if you are still running into issues please file a new ticket, include the version you are using, and enough details to allow us to diagnose the issue.
Yes, I got this...though tools are different, it seems the same reason.
We are using cnpm which is a modified version of npm that cache packages from outside China (I hate that, but I have no idea, cause that is the fast way to download packages):
But cnpm has a different package saving system ( maybe for compatibility ), it downloads packages under /usr/local/lib/node_modules/.<package name> ( the dot ) instead of common /usr/local/lib/node_modules/<package name>, and then create a link between 2nd and 1st.
Then i also run npm link <package name> for my local application. The output would look like this:
$ npm link "@types/react"
/Users/yarco/Sites/ladycat_v2/admin/node_modules/@types/react -> /usr/local/lib/node_modules/@types/react -> /usr/local/lib/node_modules/.@types/react_npminstall/node_modules/.@types/[email protected]
Then when run tsc, i got:
$ tsc
node_modules/@types/react-dom/index.d.ts(6,21): error TS2300: Duplicate identifier 'ReactDOM'.
node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
../../../../../usr/local/lib/node_modules/.@types/react-dom_npminstall/node_modules/.@types/[email protected]/index.d.ts(6,21): error TS2300: Duplicate identifier 'ReactDOM'.
../../../../../usr/local/lib/node_modules/.@types/react-dom_npminstall/node_modules/.@types/[email protected]/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
../../../../../usr/local/lib/node_modules/.@types/react_npminstall/node_modules/.@types/[email protected]/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
Any solution/tricks for now?
Update: #9091 also is the same issue.
@yarcowang
on windows, here is a workaround using a batch script with robocopy. I wrote this because the tsconfig.json based work arounds don't fix visualstudio unfortunately, as it seems to have another means of scanning solution ts files which breaks due to the same/similar issue.
:rerunloop
@echo watching for changes to project files.............. (Ctrl-C to cancel)
@rem *******************************
@rem npm link fix : copy code into node_modules of the consuming project: xlib --> blib and slib
@robocopy ..\xlib\src ..\blib\node_modules\xlib\src *.* /MIR /NJH /NJS /NDL /XD .git
@if NOT "%errorlevel%" == "0" (
@rem copy occured, so copy both
@robocopy ..\xlib\dist ..\blib\node_modules\xlib\dist *.* /MIR /NJH /NJS /NDL /XD .git
@robocopy ..\xlib\src ..\slib\node_modules\xlib\src *.* /MIR /NJH /NJS /NDL /XD .git
@robocopy ..\xlib\dist ..\slib\node_modules\xlib\dist *.* /MIR /NJH /NJS /NDL /XD .git
@rem set the src dirs readonly
@attrib +R ..\blib\node_modules\xlib\src\* /S /D
@attrib +R ..\slib\node_modules\xlib\src\* /S /D
)
@rem *******************************
@rem another alternative way to fix npm link issues: copy source code to the consuming project and have the consuming project treat it as a native part of it's project
@robocopy .\dtll-interop\src\mirror-source .\dtll-app-browser\src\dtll-interop *.* /MIR /NJH /NJS /NDL
@if NOT "%errorlevel%" == "0" (
@rem copy occured, so copy both
@robocopy .\dtll-interop\src\mirror-source .\dtll-server-dashboard\src\dtll-interop *.* /MIR /NJH /NJS /NDL
@rem and set reseults readonly
@attrib +R .\dtll-server-dashboard\src\dtll-interop\* /S /D
@attrib +R .\dtll-app-browser\src\dtll-interop\* /S /D
)
@timeout /t 1 /nobreak > NUL
@goto rerunloop
@RyanCavanaugh still having this problem on 2.2-dev.20170131, please reopen
../cim-service-locator/node_modules/@types/consul/index.d.ts(6,1): message TS4090: Conflicting definitions for 'node' found at 'G:/www/cim-service-locator/node_modules/@types/node/index.d.ts' and 'g:/www/cim-backend/services/node_modules/@types/node/index.d.ts'. Consider installing a specific version of this library to resolve the conflict.
../cim-service-locator/node_modules/@types/lodash/index.d.ts(19211,15): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
../cim-service-locator/node_modules/@types/request/index.d.ts(8,1): message TS4090: Conflicting definitions for 'node' found at 'G:/www/cim-service-locator/node_modules/@types/node/index.d.ts' and 'g:/www/cim-backend/services/node_modules/@types/node/index.d.ts'. Consider installing a specific version of this library to resolve the conflict.
unless #6496 is going to be the 'main issue' for this problem (lingering for a lot of time by now), but this shouldn't be tagged as fixed because it isn't
this is still not working!
ERROR in [at-loader] ../corifeus-web-material/node_modules/@types/hammerjs/index.d.ts:9:5
TS2300: Duplicate identifier 'export='.
ERROR in [at-loader] ../corifeus-web-material/node_modules/@types/hammerjs/index.d.ts:71:6
TS2300: Duplicate identifier 'RecognizerTuple'.
ERROR in [at-loader] ../corifeus-web-material/node_modules/@types/hammerjs/index.d.ts:139:15
TS2300: Duplicate identifier 'HammerInput'.
ERROR in [at-loader] ../corifeus-web-material/node_modules/@types/hammerjs/index.d.ts:217:15
TS2300: Duplicate identifier 'MouseInput'.
fyi there is a bug in npm that is causing issues: https://github.com/npm/npm/issues/10343
it used to work for me, but after switching my npm versions around it's broken again due to the issue I linked above.
who knows when that will get fixed....
whit this settings it works
https://github.com/patrikx3/corifeus-web-pages/blob/master/tsconfig.json
multiple linked projects
@patrikx3 thanks it works, assuming you don't run into the npm bug I mentioned above.
for those looking at Patrik's tsconfig file, the important lines are:
"baseUrl": "./",
"paths": {
"*": [
"node_modules/@types/*",
"*"
]
}
@jasonswearingen this solution doesn't work for me unfortunately. Has anyone found a solution to this problem? It really impedes being able dev npm modules locally.
you can try delete the node_modules sometimes.
not always.
it will not work always with a symlink :)
i use 2 repos. a linked and a non linked.
sometimes i remove the node_modules, sometimes i have to switch to a non link clone.
will not be perfect always.
besides i use yarn, but that not helping anyways ciao!!
@buoyad
i posted more details on my workarounds here: https://github.com/Microsoft/TypeScript/issues/6496#issuecomment-302886203
The workaround posted by @mhegazy in https://github.com/Microsoft/TypeScript/issues/11916#issuecomment-257130001 solved this for us when using linked modules in a lerna project!
Most helpful comment
Hmm, I'm not so sure the path machinery is fine actually.With this
tsconfig.jsonI get these errors
shujin is an npm linked dependency and for some reason typescript uses its modules even though node_modules is excluded.
Should I open a new issue?