LoginSignup
ConectTheDots314
@ConectTheDots314

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

package.jsonのscriptが動かない

1. 【必須】やりたい・やりたかったこと

$ yarn start

とコマンドを叩くことで、localhost:9000にアクセスでき「/index.htmlです。」と表示させたい

2. 【必須】起きている問題やエラーメッセージ ※できるだけ詳細に書いてください

  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v19.5.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

3. 【必須】ご自身で試されたこと ※できるだけ詳細に書いてください

yarn addでバージョンを指定する
https://qiita.com/suin/items/6faea73b5b16d31d990a
yarn addでバージョンを指定してNPMパッケージをインストールする方法です。

yarn add [パッケージ名]@[バージョン指定]

例: reactのバージョン^16.13.1をインストールする

yarn add 'react@^16.13.1'

完了!

yarn startしてみる

$ yarn start
yarn run v1.22.19
$ webpack-dev-server --mode development --watch
ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /Users/shouminotaku
node:internal/crypto/hash:71
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:140:10)
    at module.exports (/Users/shouminotaku/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:503:5
    at /Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:358:12
    at /Users/shouminotaku/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/shouminotaku/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/Users/shouminotaku/node_modules/loader-runner/lib/LoaderRunner.js:205:4) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v19.5.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
コマンドの実行に失敗し、終了コード 1 が表示された

ということでリンク先を見てみる
https://classic.yarnpkg.com/en/docs/cli/run

よくわからないが、

$ yarn run ~

.xmlで指定されたスクリプトの〜が実行されるようだ

とりあえず実行時に

$yarn run 

実行時にスクリプトを表示させてみる

$ yarn run
yarn run v1.22.19
info Commands available from binary scripts: acorn, ansi-html, atob, errno, he, html-minifier, import-local-fixture, json5, miller-rabin, mime, mkdirp, multicast-dns, rimraf, semver, sha.js, terser, uglifyjs, uuid, webpack, webpack-cli, webpack-dev-server, which
info Project commands
   - start
      webpack-dev-server --mode development --watch
question Which command would you like to run?: start
$ webpack-dev-server --mode development --watch
ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /Users/shouminotaku
node:internal/crypto/hash:71
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:140:10)
    at module.exports (/Users/shouminotaku/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:503:5
    at /Users/shouminotaku/node_modules/webpack/lib/NormalModule.js:358:12
    at /Users/shouminotaku/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/shouminotaku/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/Users/shouminotaku/node_modules/loader-runner/lib/LoaderRunner.js:205:4) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v19.5.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

とりあえずstartは使用できるようだ。

もしかするとエラーの原因は、node.jsのバージョンが新しすぎることかもしれない。
https://ki-hi-ro.com/what-is-nuxt-js/

参考にするも、実際に打てばいいかわからなかった。

4. 関連するソースコードやスクリーンショット

package.json

{
  "name": "01",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "ejs-compiled-loader": "1.1.0",
    "html-webpack-plugin": "3.2.0",
    "webpack": "4.46.0",
    "webpack-cli": "3.3.12",
    "webpack-dev-server": "3.10.1"
  },
  "scripts": {
    "start": "webpack-dev-server --mode development --watch"
  }
}

index.ejs
/index.htmlです。

0

3Answer

Node.js17以降のバージョンではOpenSSLの関係でWebpack 4.xは動作できなくなっています.

NODE_OPTIONS=--openssl-legacy-providerの指定で対応可能ですが,今あえてWebpack 4に拘る理由がない限り推奨しません.

なお,Node.jsを利用したプロダクションコードはNode.js LTSで開発されることが原則とされていますので,Node.jsはよほどのことがない限りLTS(2/2現在18.13.0)を使用してください.

1Like

Comments

  1. お忙しい中、丁寧に回答いただきありがとうございます。

    改めてNode.jsのバージョンをLTSに改めて再度$yarn startしてみたのですがエラーが出てしまいました。
    自分なりに調べてみたのですが下の投稿をみていただけますでしょうか。

お忙しい中回答いただきありがとうございます。

ソースコード
https://github.com/Taku-Omino/practice/tree/main/01

エラーの原因を改めて考えてみたのですが、

ERROR in Entry module not found: Error: Can't resolve './src' in '/Users/shouminotaku'

ERROR in multi (webpack)-dev-server/client?http://localhost:8080 ./src
Module not found: Error: Can't resolve './src' in '/Users/shouminotaku'
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src main[1]

Webpackが指定された './src' ディレクトリを見つけられないことを示している。

自分なりに確認したこと

  1. './src' ディレクトリが存在していないか。
  2. './src' ディレクトリが存在するが、Webpackの設定ファイル(通常はwebpack.config.js)で指定されていない
  3. './src' ディレクトリが存在するが、Webpackの設定ファイル(通常はwebpack.config.js)で指定されているが、間違っている

上の3が怪しい気がしているのですが、どなたかご教示していただけるとありがたいです。

よろしくお願いします。

0Like

改めてNode.jsのバージョンをLTSに改めて再度$yarn startしてみたのですがエラーが出てしまいました。

ERROR in Entry module not found: Error: Can't resolve './src' in '/Users/shouminotaku'

単にコマンドを実行するディレクトリが間違っているのでは?
プロジェクトのディレクトリで操作するのが基本です.

0Like

Your answer might help someone💌