1
votes

lancer un nouveau JS_Parse_Error (message, nom de fichier, ligne, col, pos) lors de l'utilisation de usemin-cli

J'utilise usemin-cli pour réduire mes fichiers html. J'ai installé toutes les dépendances requises pour utiliser usemin-cli . J'essaie le script usemin npm suivant pour terminer cette tâche: -

> usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html


undefined:1625
    throw new JS_Parse_Error(message, filename, line, col, pos);
    ^
SyntaxError: Unexpected token: name (o)
    at JS_Parse_Error.get (eval at <anonymous> (/home/neo/Desktop/full stack coursera/Web Ui with bootstrap(course1)/bootstrap4-starter/conFusion/node_modules/usemin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:86:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion@1.0.0 usemin: `usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion@1.0.0 usemin script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/neo/.npm/_logs/2019-01-17T10_30_03_425Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion@1.0.0 build: `npm run clean && npm run copyfonts && npm run imagemin && npm run usemin`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/neo/.npm/_logs/2019-01-17T10_30_03_525Z-debug.log

Il réduit uniquement les index.html et contactus.html et donne une erreur à aboutus.html . Voici aboutus.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie-edge">
  <!-- build:css css/main.css -->
  <link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="./node_modules/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="./node_modules/bootstrap-social/bootstrap-social.css">
  <link rel="stylesheet" href="./css/styles.css">
  <!-- endbuild -->
  <title>Ristorante Con Fusion</title>
</head>

<body>

    <!-- build:js js/main.js -->
  <script src="./node_modules/jquery/dist/jquery.min.js"></script>
  <script src="./node_modules/popper.js/dist/umd/popper.min.js"></script>
  <script src="./node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="./js/scripts.js"></script>
  <!-- endbuild -->
</body>

</html>

Voici index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie-edge">
  <title>Ristorante Con Fusion: About Us</title>
  <!-- build:css css/main.css -->
  <link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="./node_modules/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="./node_modules/bootstrap-social/bootstrap-social.css">
  <link rel="stylesheet" href="./css/styles.css">
  <!-- endbuild -->
</head>

<body>
 <!-- here is my body code using bootstrap and html -->
  <!-- build:js js/main.js -->
  <script src="./node_modules/jquery/dist/jquery.min.js"></script>
  <script src="./node_modules/popper.js/dist/popper.min.js"></script>
  <script src="./node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="./js/scripts.js"></script>
  <!-- endbuild -->
</body>

</html>

Erreur lors de l'exécution après la npm run build :

"scripts": {
    "start": "npm run watch:all",
    "test": "echo \"Error: no test specified\" && exit 1",
    "lite": "lite-server",
    "scss": "node-sass -o css/ css/",
    "watch:scss": "onchange './css/*.scss' -- npm run scss",
    "watch:all": "parallelshell 'npm run watch:scss'",
    "clean": "rimraf dist",
    "copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/fonts",
    "imagemin": "imagemin img/* --out-dir dist/img",
    "usemin": "usemin index.html -d dist --htmlmin -o dist/index.html && usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html",
    "build": "npm run clean && npm run copyfonts && npm run imagemin && npm run usemin"
  }

Que dois-je faire pour résoudre ce problème?


0 commentaires

4 Réponses :


1
votes

le problème peut se trouver dans votre fichier scripts.js, mais essayez d'abord de faire le test suivant, étape par étape.

à partir de votre package.json ... change (ajoutez seulement un autre fichier * .html, mais nous allons maintenant essayer avec un seul fichier * .html)

npm run usemin

à

   <!-- build:js js/main.js -->
   <script src="node_modules/jquery/dist/jquery.min.js"></script>
   <script src="node_modules/tether/dist/js/tether.min.js"></script>
   <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
   <!-- endbuild -->
   <script src="js/scripts.js"></script>

si cela ne fonctionne pas, conservez les modifications et essayez ceci

à partir de votre * .html ... modifier

   <!-- build:js js/main.js -->
   <script src="node_modules/jquery/dist/jquery.min.js"></script>
   <script src="node_modules/tether/dist/js/tether.min.js"></script>
   <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
   <script src="js/scripts.js"></script>
   <!-- endbuild -->

à

"usemin": "usemin index.html -d dist -o dist/index.html --htmlmin true",

courir

"usemin": "usemin index.html -d dist --htmlmin -o dist/index.html",

si voir votre dossier dist et le chemin complet avec les dossiers css et js et les fichiers html; la conclusion est que vous devez vérifier la syntaxe de JavaScript à partir de votre fichier scripts.js.


0 commentaires

0
votes

Assalamu Alaykum.

Dans votre fichier aboutus.html, vous incluez un chemin incorrect pour le fichier popper.min.js

Voici votre mauvais chemin

<script src="./node_modules/popper.js/dist/umd/popper.min.js"></script>

Ça devrait être.

 <script src="./node_modules/popper.js/dist/popper.min.js"></script>

Vous pouvez vérifier le chemin source de vos fichiers index.html popper.min.js et il était correct.


0 commentaires

0
votes

J'obtenais la même erreur parce que j'utilisais les fonctions fléchées et jQuery, j'ai donc supprimé les fonctions fléchées (la suppression du code jQuery fonctionnera également) et cela s'est déroulé sans erreur:

    "usemin": "usemin aboutus.html -d dist -o dist/aboutus.html --htmlmin true && usemin contactus.html -d dist -o dist/contactus.html --htmlmin true && usemin index.html -d dist -o dist/index.html --htmlmin true"


0 commentaires

0
votes

J'ai eu le même problème et la solution Assalamu Alaykum a fonctionné pour moi. Ce n'était pas un problème de fichier de scripts .js, c'était juste le script popper.

Changer en

<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>

travaillé pour moi.


0 commentaires