【问题标题】:how to include jquery from node_modules in angular1如何在angular1中包含来自node_modules的jquery
【发布时间】:2018-07-11 22:42:21
【问题描述】:

这是我的 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 我的申请

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

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); 

运行节点server.js时出现以下错误: 本地主机/:12 获取 http://localhost:8081/node_modules/jquery/dist/jquery.min.js404(未找到)

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.

我有node_modules/jquery/dist/jquery.min.js,但我不知道为什么会出现此错误。

【问题讨论】:

  • 你是不是打错了……header.ejs实际上是header.js还是不是?
  • 只有header.ejs文件。
  • 也分享server.js代码
  • 好的,我会更新
  • @VilasKumkar 更新

标签: jquery angularjs


【解决方案1】:

您实际上是在尝试提供静态资源,因此您必须启用一个路径来定位您的静态文件,如脚本、css、图像等

如果您使用 Expressjs 作为后端,请查看此链接 http://expressjs.com/es/starter/static-files.html

【讨论】:

  • 是的,我已经添加了那个......现在我也更新了我的 server.js 代码
  • 实际上您想从该路径提供 jquery.min.js,例如 /static/js/jquery.min.js,而不是 ../node_modules/... 等
【解决方案2】:

解决方案:

我解决了这个问题,我在 server.js 中声明了静态路径路由,所以这是我的静态路径, 所以我必须从该路径调用文件,例如 (../node_modules/jquery/dist/jquery.min.js)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多