Problem z uruchamianiem pakietów

0

Witam..

Od jakiegoś czasu chcąc użyć jakiegokolwiek pakietu z NPM w node nie mogę tego zrobić. Dotąd problem nigdy nie występował.

Tworze w folderze z projektem plik package.json poprzez npm init, przykładowo dodaję jshint, folder node_modules/ tworzony jest poprawnie. W nim bin/ itd... próbując wywołać w terminalu VSCode czy cmd node node_modules/.bin/jshint na konkretnym pliku czyli js/classes.js w moim przypadku czy jakikolwiek inny kończy się to tak jak poniżej. Pliku lub ścieżki do niego mogę w ogóle nie podać a problem jest ciągle ten sam. Dodam, że przeinstalowałem node i nic... kompletnie, już nie wiem co mam robić.

Ciągle wypluwa takie jakieś błędy, które jakby informowały, że to z pakietem jshint jest coś nie tak. Ale jakikolwiek inny też zgłasza błąd przy próbie odpalenia go.

c:\Users\NanoSoft\Desktop\app\node_modules\.bin\jshint:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^
  
SyntaxError: missing ) after argument list
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1032:15)
    at Module._compile (node:internal/modules/cjs/loader:1067:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

Jak można to rozwiązać ?

0

Zamiast przekazywać ścieżkę do node_modules node node_modules/.bin/jshint, spróbuj skróconej wersji npx jshint.

0

Teraz działa jak najbardziej.
Dziękuję za pomoc :)

0

Niestety kolejny problem wystąpił z webpackiem.
Czy użyje go z npx czy jakikolwiek inny sposób mam takie oto błędy:

assets by status 0 bytes [cached] 1 asset

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value.
Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in main
Module not found: Error: Can't resolve 'dist/bundle.js' in 'c:\Users\NanoSoft\Desktop\65\start'
resolve 'dist/bundle.js' in 'c:\Users\NanoSoft\Desktop\65\start'
  Parsed request is a module
  using description file: c:\Users\NanoSoft\Desktop\65\start\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in c:\Users\NanoSoft\Desktop\65\start\node_modules
        c:\Users\NanoSoft\Desktop\65\start\node_modules\dist doesn't exist
      c:\Users\NanoSoft\Desktop\65\node_modules doesn't exist or is not a directory
      c:\Users\NanoSoft\Desktop\node_modules doesn't exist or is not a directory
      c:\Users\NanoSoft\node_modules doesn't exist or is not a directory
      c:\Users\node_modules doesn't exist or is not a directory
      c:\node_modules doesn't exist or is not a directory

ERROR in main
Module not found: Error: Can't resolve 'src/js/scripts.js' in 'c:\Users\NanoSoft\Desktop\65\start'
Did you mean './src/js/scripts.js'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
resolve 'src/js/scripts.js' in 'c:\Users\NanoSoft\Desktop\65\start'
  Parsed request is a module
  using description file: c:\Users\NanoSoft\Desktop\65\start\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in c:\Users\NanoSoft\Desktop\65\start\node_modules
        c:\Users\NanoSoft\Desktop\65\start\node_modules\src doesn't exist
      c:\Users\NanoSoft\Desktop\65\node_modules doesn't exist or is not a directory
      c:\Users\NanoSoft\Desktop\node_modules doesn't exist or is not a directory
      c:\Users\NanoSoft\node_modules doesn't exist or is not a directory
      c:\Users\node_modules doesn't exist or is not a directory
      c:\node_modules doesn't exist or is not a directory

webpack 5.71.0 compiled with 2 errors and 1 warning in 221 ms

c:\Users\NanoSoft\Desktop\65\start>node webpack
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'c:\Users\NanoSoft\Desktop\65\start\webpack'
←[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)←[39m
←[90m    at node:internal/main/run_main_module:17:47←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: []
}
0

No okej, ale teraz komunikat jasno mówi w czym jest problem. Wyświetla się nawet adres do fragmentu dokumentacji, który pomoże Ci poprawić jeden z problemów https://webpack.js.org/configuration/mode/

Musisz poprawić konfigurację webpacka.

0

oczywiście, próbowałem to robić robić z poziomu zmienić na development czy production ale bez skutku

0

Tam jest kilka błędów/ostrzeżeń:

  1. Problem z opcją mode w konfiguracji webpacka,
  2. Problem z folderem dist (Module not found: Error: Can't resolve 'dist/bundle.js'),
  3. Problem z folderem src (Module not found: Error: Can't resolve 'src/js/scripts.js')

Musisz sprawdzić jeszcze raz tą konfigurację, bo z tego co pamiętam to webpack przyjmuje ścieżki relatywne, czyli coś takiego ./src/js/scripts.js i to się różni od tego co masz obecnie src/js/scripts.js.

Najlepiej to przejrzeć strukturę projektu i porównać to z konfiguracją webpacka

1 użytkowników online, w tym zalogowanych: 0, gości: 1