Выбросить новый JS_Parse_Error (сообщение, имя файла, строка, столбец, позиция) при использовании usemin-cli

Я использую usemin-cli для минимизации своих файлов html. Я установил все необходимые зависимости для использования usemin-cli. Я пробую следующий сценарий usemin npm для выполнения этой задачи: -

"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"
  }

Он минимизирует только index.html и contactus.html и выдает ошибку на aboutus.html. Вот 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">
  <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>

Вот 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">
  <!-- 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>

Ошибка запуска после npm run build:

> 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! [email protected] usemin: `usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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! [email protected] 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 [email protected] 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

Что мне делать, чтобы решить эту проблему?

Настройка шаблона Metronic с помощью Webpack и Gulp
Настройка шаблона Metronic с помощью Webpack и Gulp
Я пишу эту статью, чтобы поделиться тем, как настроить макет Metronic с помощью Sass, поскольку Metronic предоставляет так много документации, и они...
2
0
925
4

Ответы 4

the issue might be in your scripts.js file but first, try to do the next test, step by step.

из вашего package.json ... изменить (добавьте только другой файл * .html, но теперь мы попробуем только один файл * .html)

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

к

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

если не работает, сохраните изменения и попробуйте это

из вашего * .html ... изменить

   <!-- 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 -->

к

   <!-- 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>

бегать

npm run usemin

if see your dist folder and the complete path with css and js folders and html files; the conclusion is, you need to check the syntax of JavaScript from you scripts.js file.

Ассаламу Алайкум .

В вашем файле aboutus.html вы указываете неправильный путь для файла popper.min.js

Вот твой неверный путь

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

Должен быть.

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

Вы можете проверить исходный путь файла index.html popper.min.js, и он был правильным.

Я получал ту же ошибку, потому что использовал стрелочные функции и jQuery, поэтому я удалил стрелочные функции (удаление кода jQuery тоже будет работать), и это прошло без ошибок:

    "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"

У меня была та же проблема, и решение Assalamu Alaykum сработало для меня. Это была не проблема с файлом сценария .js, это был просто сценарий popper.

Переход на

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

работал у меня.

Другие вопросы по теме