Jquery not working in angular 6 Error: ENOENT: no such file or directory, open '…\node_modules\jquery\dist\jquery.min.js'

前端 未结 11 1687
离开以前
离开以前 2021-02-01 02:02

I am in process migrating Angular 5 project to Angular 6.

While starting application by

npm start

getting the below error



        
相关标签:
11条回答
  • 2021-02-01 02:38

    In Angular 6 u don't need to write:

    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/tether/dist/js/tether.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js"
    

    You can write with ./ like on the top this will works too, but the easiest way in angular.json file:

    "node_modules/jquery/dist/jquery.js",
    "node_modules/tether/dist/js/tether.js",
    "node_modules/bootstrap/dist/js/bootstrap.js"
    

    In my opinion it's better and clear

    0 讨论(0)
  • 2021-02-01 02:39

    For Angular 6 the path is as follows:

    from:

    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/tether/dist/js/tether.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js"
    

    to

    "./node_modules/jquery/dist/jquery.js",
    "./node_modules/tether/dist/js/tether.js",
    "./node_modules/bootstrap/dist/js/bootstrap.js"
    
    0 讨论(0)
  • 2021-02-01 02:46

    Paths in angular-cli.json are relative to the project root (src/ normally). For instance, you have the src/styles.css file, but in angular-cli.json it's listed only as styles.css.

    0 讨论(0)
  • 2021-02-01 02:49

    In your file 'tsconfig.json', you make maybe

    {
      "compileOnSave": false,
      "compilerOptions": {
      "baseUrl": "./",
      "outDir": "./dist/out-tsc",
      "sourceMap": true,
      "declaration": false,
      "moduleResolution": "node",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "target": "es5",
      "typeRoots": [
      "node_modules/@types"
      ],
      "lib": [
        "es2017",
        "dom"
      ]
     },
    "include": ["node_modules/angular-bootstrap-md/**/*.ts",  "src/**/*.ts"], 
    }
    

    You can replace

    "include": ["node_modules/angular-bootstrap-md/**/*.ts",  "src/**/*.ts"],
    

    to

    "include": ["src/**/*.ts","node_modules/angular-bootstrap-md/**/*.ts" ],
    

    Moreover, in your file 'angular.json', I delete '../' in front of node_modules in "styles" and "scripts".

    And I copied lines of the "scripts" in the "scripts" in the category "test"

    "test": {
         ...
         "styles": [
           "src/styles.css"
            "node_modules/bootstrap/dist/css/bootstrap.min.css",
            "./assets/css/font-icon.css",
            "node_modules/font-awesome/css/font-awesome.css"
         ],
         "scripts": [
            "node_modules/jquery/dist/jquery.min.js",
            "node_modules/popper.js/dist/umd/popper.min.js",
            "node_modules/bootstrap/dist/js/bootstrap.min.js"
         ],
         ...
    
    0 讨论(0)
  • 2021-02-01 02:53

    Once again the angular team makes things harder for not real reason =(

    I had this problem and after Googling around fruitlessly I wondered if they had changed relative paths somehow as well as renaming angular-cli.json.

    A little further up in the file I found the line:

    Yeah, just change:

    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/tether/dist/js/tether.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js"
    

    to

    "./node_modules/jquery/dist/jquery.js",
    "./node_modules/tether/dist/js/tether.js",
    "./node_modules/bootstrap/dist/js/bootstrap.js"
    
    0 讨论(0)
提交回复
热议问题