0

I installed jquery-datatimepicker by adding jquery.datetimepicker.min.css and jquery.datetimepicker.full.min.js in angular.json and put them in node_modules/datetimepick folder

angular.json:

        ..
        "styles": [
          "src/styles.scss",
          "node_modules/datatables.net-dt/css/jquery.dataTables.css",
          "node_modules/datatables.net-responsive-dt/css/responsive.dataTables.css",
          "node_modules/bootstrap/dist/css/bootstrap.css",
          "node_modules/bootstrap/dist/css/bootstrap-reboot.css",
          "node_modules/bootstrap/dist/css/bootstrap-grid.css",
          "node_modules/datetimepicker/jquery.datetimepicker.min.css"
        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/jquery/dist/popper-1.11.0.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.js",
          "node_modules/dropify/dist/js/dropify.js",
          "node_modules/datatables.net/js/jquery.dataTables.js",
          "node_modules/datatables.net-responsive/js/dataTables.responsive.js",
          "node_modules/datetimepicker/jquery.datetimepicker.full.min.js"
        ]

But every time when I use npm install or npm install new-package, the node_modules/datetimepicker/ folder always got removed and I need to add the folder and files by myself.

Any suggestions could solve this problem?

Angular CLI: 8.3.8
Node: 13.13.0
OS: win32 x64
Angular: 8.2.9

Note: I have tried this solution and I only want to use the external JS/CSS solution.

Alan Yu
  • 1,462
  • 12
  • 21
  • 2
    `node_modules` is an internal folder used by npm, you should never add your own files there. During an npm install, the package.json is analyzed. Packages which are no dependency and also no sub-dependency of your project, will be removed. So this is intended behaviour. Why you don't install `jquery-datetimepicker` via npm? – JSON Derulo Nov 18 '21 at 13:58
  • 2
    Additionally, the content of the `node_modules` should **never** be pushed to your version control system. So with your approach, how should another person working on the project get the required files for the datetimepicker? – JSON Derulo Nov 18 '21 at 14:00
  • @JSONDerulo I tried but it always show $().datetimepicker is not a function error. and I could not solve this problem even google it again and again – Alan Yu Nov 18 '21 at 14:00
  • @JSONDerulo by adding datetimepicker folder by himself – Alan Yu Nov 18 '21 at 14:01
  • 1
    So either you get it running via an npm install, or you place the files in another folder than `node_modules`. – JSON Derulo Nov 18 '21 at 14:07
  • @JSONDerulo thx, i put it in the asset folder, and use npm install, it works well. – Alan Yu Nov 18 '21 at 14:16

1 Answers1

0

This is obvious because in your package.json file this package is not available and npm install all the dependencies from the package.json. try to install

npm i jquery-datepicker

now you will have all the dependencies along with jquery-datepicker

if jquery-datepicker is not available in the package.json npm will not install it.

U.Aasd
  • 1,396
  • 1
  • 8
  • 11