Jordi
Jordi

Reputation: 23187

webpack: npm package dependency not resolved (typescript, angular)

I'm getting this error:

ERROR in ./node_modules/ts-odatajs/lib/xml.js
Module not found: Error: Can't resolve 'xmldom' in 'D:\projects\swiller\querydsl\angular-starter\node_modules\ts-odataj
\lib'
 @ ./node_modules/ts-odatajs/lib/xml.js 183:25-42
 @ ./node_modules/ts-odatajs/index.js
 @ ./src/app/home/home.component.ts
 @ ./src/app/home/index.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.browser.ts
 @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts

My project structure is like:

project/src/app
├───home
│   │   home.component.css
│   │   home.component.html
│   │   home.component.spec.ts
│   │   home.component.ts
│   │   home.e2e.ts
│   │   index.ts

I've installed ts-odatajs npm package: npm install --save ts-odatajs. Into home.component.ts I've imported some exports from ts-odatajs:

import { oData } from 'ts-odatajs';

I don't quite figure out where's the error. Any ideas?

EDIT

This is the output when I install ts-odatajs:

PS D:\projects\swiller\querydsl\angular-starter> npm install --save ts-odatajs
[email protected] D:\projects\swiller\querydsl\angular-starter
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- [email protected]
`-- UNMET PEER DEPENDENCY [email protected]

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any
"} (current: {"os":"win32","arch":"x64"})
npm WARN @angular/[email protected] requires a peer of typescript@>=2.4.2 <2.5 but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none was installed.
npm WARN [email protected] requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.

EDIT 2

"dependencies": {
    "@angular/animations": "~5.1.0",
    "@angular/common": "~5.1.0",
    "@angular/compiler": "~5.1.0",
    "@angular/core": "~5.1.0",
    "@angular/forms": "~5.1.0",
    "@angular/platform-browser": "~5.1.0",
    "@angular/platform-browser-dynamic": "~5.1.0",
    "@angular/platform-server": "~5.1.0",
    "@angular/router": "~5.1.0",
    "core-js": "^2.5.1",
    "http-server": "^0.10.0",
    "ie-shim": "^0.1.0",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.5.2",
    "ts-odatajs": "^4.0.2",
    "zone.js": "~0.8.18"
  },

EDIT 3

I've just realized that packages.json has xmldom package as devDependency: See here

Upvotes: 1

Views: 662

Answers (1)

Travis Schettler
Travis Schettler

Reputation: 854

Looks like Apache's original setup for the package dependencies doesn't work well with Angular 5. I had previously tested the package with Angular 4. I think this needs to be listed under dependencies, rather than devDependencies. I'll get this updated in another release.

In the meanwhile, to resolve the issue, you can simply manually install the version of xmldom that it is looking for:

npm install [email protected] --save

Upvotes: 1

Related Questions