You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ng2-daterangepicker构建报错:导入时未从node_modules读取包

Fix: "No such file or directory found on project root" when importing ng2-daterangepicker

I’ve run into this exact issue before with ng2-daterangepicker—let’s walk through the fixes that worked for me:

1. Verify the package is properly installed

First, double-check that the package exists in your node_modules directory. If it’s missing, reinstall it with:

npm install ng2-daterangepicker --save
# Or if using yarn
yarn add ng2-daterangepicker

If it’s already present, try a clean reinstall to fix any corrupted or incomplete files:

  • Delete your node_modules folder
  • Delete package-lock.json (or yarn.lock)
  • Run npm install again

2. Check TypeScript module resolution settings

Make sure your tsconfig.json is configured to resolve modules from node_modules correctly. In the compilerOptions section, confirm these settings:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "baseUrl": "./",
    // Other existing options...
  }
}

The moduleResolution: "node" flag tells TypeScript to use Node.js-style module resolution, which prioritizes looking in node_modules over your project root.

3. Confirm the correct import path

Sometimes the package’s entry point isn’t at the root of the npm package. Check the main or module field in node_modules/ng2-daterangepicker/package.json—if it points to a subdirectory like lib/index.js, adjust your import to match:

import { Daterangepicker } from 'ng2-daterangepicker/lib';

4. Ensure Angular version compatibility

Older versions of ng2-daterangepicker might not work with newer Angular releases. Check the package’s documentation to confirm it supports your Angular version, and upgrade/downgrade the package accordingly if needed.

5. Clear the Angular build cache

If you’re using Angular CLI, outdated cache can cause path resolution issues. Clear it with:

ng cache clean

内容的提问来源于stack exchange,提问作者ahsan ahmad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:31:54