简体   繁体   English

如何在angular1中包含来自node_modules的jquery

[英]how to include jquery from node_modules in angular1

Here this is my HTML: 这是我的HTML:

<!DOCTYPE html>
<html>
<head><% include ./header %>
<link type="text/javascript" src="loginScript" ></head>
<body class='home-page' ng-app="loginApp" ng-controller="LoginCtrl"> </body></html>

header.ejs My application header.ejs我的应用程序

 <script type="text/javascript" src="/node_modules/jquery/dist/jquery.min.js"> 
 </script> 

server.js server.js

      var express = require('express');
      var app = express();
      var mysql = require('mysql');
      var path = require('path');
      var http = require('http');
      var fs = require('fs');
      var bodyParser = require('body-parser');
      app.set('view engine','ejs');

      app.get('/',(req,res) =>{
         res.render('./login_page');
      });
      app.use(express.static(path.join(__dirname, 'public')));
      var server = http.createServer();
      app.listen(8081); 

While running node server.js the following error is displayed: localhost/:12 GET http://localhost:8081/node_modules/jquery/dist/jquery.min.js 404 (Not Found) 运行节点server.js ,显示以下错误:localhost /:12 GET http:// localhost:8081 / node_modules / jquery / dist / jquery.min.js 404(未找到)

localhost/:1 Refused to execute script from 
'http://localhost:8081/node_modules/jquery/dist/jquery.min.js' because 
its MIME type ('text/html') is not executable, and strict MIME type 
checking is enabled.

I have node_modules/jquery/dist/jquery.min.js but i don't know why i am getting this error. 我有node_modules/jquery/dist/jquery.min.js但是我不知道为什么我得到这个错误。

You are actually triying to serve a static resource, so you have to enable a path where locate your static files like scripts, css, images, etc 您实际上是在尝试提供静态资源,因此必须启用一个路径,在该路径中可以找到静态文件,例如脚本,css,图像等。

If you are using Expressjs for the backend, check this link out http://expressjs.com/es/starter/static-files.html 如果您将Expressjs用于后端,请在http://expressjs.com/es/starter/static-files.html中查看此链接。

Solution: 解:

I solved this issue,I am declared static path route in server.js so that is my static path, so I have to call the file from that path like (../node_modules/jquery/dist/jquery.min.js) 我解决了这个问题,我在server.js中声明了静态路径路由,因此这是我的静态路径,因此我必须从该路径中调用文件,例如(../node_modules/jquery/dist/jquery.min.js)

  <script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js"> 
  </script> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从node_modules中包含JQuery,除了Laravel 5.8 app中的cdn? - How to include JQuery from node_modules, except from cdn in Laravel 5.8 app? 在 node_modules 文件夹中找不到 jQuery 和引导程序 - jQuery and bootstrap not found in node_modules folder 如何将 node_modules 中的插件添加到 Laravel mix - How to add plugins from node_modules to Laravel mix Angular node_modules:正确包含JQuery并防止“未定义窗口”错误 - Angular node_modules: Including JQuery properly with also preventing the “window is not defined” error Jquery 不能在 angular 6 中工作错误:ENOENT:没有这样的文件或目录,打开“…\\node_modules\\jquery\\dist\\jquery.min.js” - Jquery not working in angular 6 Error: ENOENT: no such file or directory, open '…\node_modules\jquery\dist\jquery.min.js' 错误:ENOENT:没有这样的文件或目录,打开 'E:\Projects\eLearning\node_modules\jquery\dist\jquery.js' - Error: ENOENT: no such file or directory, open 'E:\Projects\eLearning\node_modules\jquery\dist\jquery.js' “node_modules”文件夹的用途是什么? - What is the purpose of the 'node_modules' folder? 使用JQuery打开/关闭Angular1 data-ng-click事件 - Turn on/off Angular1 data-ng-click event using JQuery 无法获取JavaScript文件来加载node_modules依赖项 - Can't get javascript file to load node_modules dependencies 使用 load_paths 时未找到 Jekyll node_modules - Jekyll node_modules not found while using load_paths
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM