質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

解決済

1回答

846閲覧

既存のリポジトリにライブラリを追加するには?

Eai

総合スコア18

npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2018/04/11 08:05

編集2018/04/11 08:09

node、webpackのビギナーです。

GASをTypeScriptで書くために以下の記事を参考に環境を用意しました。

Google Apps Script をローカル環境で快適に開発するためのテンプレートを作りました - Qiita

ビルドやデプロイも問題なくできたため、実際にコードを書き始め、HTMLをパースする必要があったためcheerio-httpcliを使うことにしました。

Node.js用のスクレイピングモジュール「cheerio-httpcli」の紹介 - Qiita

以下のコマンドでcheerio-httpcliをインストールしました。

npm install --save-dev cheerio-httpcli

インストールは問題なく終わり、package.jsondevDependenciesにも"cheerio-httpcli": "^0.7.2",が追加されたことを確認しました。

./src/index.tsの1行目にvar client = require('cheerio-httpcli');と追記してnpm run buildを実行するとエラーがでました。

text

1ERROR in ./node_modules/cheerio-httpcli/index.js 2Module not found: Error: Can't resolve './lib/core' in 'C:\Users\eai\source\repos\clasp\node_modules\cheerio-httpcli' 3 @ ./node_modules/cheerio-httpcli/index.js 1:17-38 4 @ ./src/index.ts

.\node_modules\cheerio-httpcli\libを確認したところcore.jsが存在していました。

調べるとこのjsをwebpackが読めていないためと分かったため、
webpack.config.json

json

1 resolve: { 2 extensions: [".ts",".js"] 3 },

と追記してjsを読むようにしました。

再びnpm run buildを実行するとエラーがでました。

text

1> gas-clasp-starter@1.0.0 build C:\Users\eai\source\repos\clasp 2> npm run lint && npm run test && rimraf dist && webpack && cpx src/appsscript.json dist 3 4 5> gas-clasp-starter@1.0.0 lint C:\Users\eai\source\repos\clasp 6> tslint --fix src/**/*.ts 7 8 9> gas-clasp-starter@1.0.0 test C:\Users\eai\source\repos\clasp 10> jest 11 12Hash: 7a2d20fb0c2d46d91615 13Version: webpack 4.1.1 14Time: 5489ms 15Built at: 2018-4-11 17:02:33 16 Asset Size Chunks Chunk Names 17bundle.js 3.82 MiB main [emitted] [big] main 18Entrypoint main [big] = bundle.js 19 [0] util (ignored) 15 bytes {main} [built] 20 [1] util (ignored) 15 bytes {main} [built] 21 [2] readable-stream (ignored) 15 bytes {main} [built] 22 [3] buffer (ignored) 15 bytes {main} [optional] [built] 23 [4] crypto (ignored) 15 bytes {main} [optional] [built] 24[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {main} [built] 25 [5] crypto (ignored) 15 bytes {main} [built] 26[./node_modules/cheerio-httpcli/lib sync recursive] ./node_modules/cheerio-httpcli/lib sync 160 bytes {main} [optional] [built] 27[./node_modules/cheerio-httpcli/lib/cheerio sync recursive ^./.*$] ./node_modules/cheerio-httpcli/lib/cheerio sync ^./.*$ 388 bytes {main} [built] 28[./node_modules/require-uncached sync recursive] ./node_modules/require-uncached sync 160 bytes {main} [built] 29 [6] vertx (ignored) 15 bytes {main} [optional] [built] 30[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {main} [built] 31[./src/index.ts] 403 bytes {main} [built] 32 + 492 hidden modules 33 34WARNING in ./node_modules/require-uncached/index.js 3528:8-25 Critical dependency: the request of a dependency is an expression 36 @ ./node_modules/require-uncached/index.js 37 @ ./node_modules/cheerio-httpcli/lib/client.js 38 @ ./node_modules/cheerio-httpcli/lib/core.js 39 @ ./node_modules/cheerio-httpcli/index.js 40 @ ./src/index.ts 41 42WARNING in ./node_modules/cheerio-httpcli/lib/encoding.js 4349:24-39 Critical dependency: the request of a dependency is an expression 44 @ ./node_modules/cheerio-httpcli/lib/encoding.js 45 @ ./node_modules/cheerio-httpcli/lib/core.js 46 @ ./node_modules/cheerio-httpcli/index.js 47 @ ./src/index.ts 48 49WARNING in ./node_modules/spawn-sync/lib/spawn-sync.js 50Module not found: Error: Can't resolve 'try-thread-sleep' in 'C:\Users\eai\source\repos\clasp\node_modules\spawn-sync\lib' 51 @ ./node_modules/spawn-sync/lib/spawn-sync.js 10:10-37 52 @ ./node_modules/spawn-sync/index.js 53 @ ./node_modules/cheerio-httpcli/lib/client.js 54 @ ./node_modules/cheerio-httpcli/lib/core.js 55 @ ./node_modules/cheerio-httpcli/index.js 56 @ ./src/index.ts 57 58ERROR in ./node_modules/spawn-sync/index.js 59Module not found: Error: Can't resolve 'child_process' in 'C:\Users\eai\source\repos\clasp\node_modules\spawn-sync' 60 @ ./node_modules/spawn-sync/index.js 3:17-41 61 @ ./node_modules/cheerio-httpcli/lib/client.js 62 @ ./node_modules/cheerio-httpcli/lib/core.js 63 @ ./node_modules/cheerio-httpcli/index.js 64 @ ./src/index.ts 65 66ERROR in ./node_modules/spawn-sync/lib/spawn-sync.js 67Module not found: Error: Can't resolve 'child_process' in 'C:\Users\eai\source\repos\clasp\node_modules\spawn-sync\lib' 68 @ ./node_modules/spawn-sync/lib/spawn-sync.js 6:9-33 69 @ ./node_modules/spawn-sync/index.js 70 @ ./node_modules/cheerio-httpcli/lib/client.js 71 @ ./node_modules/cheerio-httpcli/lib/core.js 72 @ ./node_modules/cheerio-httpcli/index.js 73 @ ./src/index.ts 74 75ERROR in ./node_modules/request/lib/har.js 76Module not found: Error: Can't resolve 'fs' in 'C:\Users\eai\source\repos\clasp\node_modules\request\lib' 77 @ ./node_modules/request/lib/har.js 3:9-22 78 @ ./node_modules/request/request.js 79 @ ./node_modules/request/index.js 80 @ ./node_modules/cheerio-httpcli/lib/client.js 81 @ ./node_modules/cheerio-httpcli/lib/core.js 82 @ ./node_modules/cheerio-httpcli/index.js 83 @ ./src/index.ts 84 85ERROR in ./node_modules/spawn-sync/lib/spawn-sync.js 86Module not found: Error: Can't resolve 'fs' in 'C:\Users\eai\source\repos\clasp\node_modules\spawn-sync\lib' 87 @ ./node_modules/spawn-sync/lib/spawn-sync.js 4:9-22 88 @ ./node_modules/spawn-sync/index.js 89 @ ./node_modules/cheerio-httpcli/lib/client.js 90 @ ./node_modules/cheerio-httpcli/lib/core.js 91 @ ./node_modules/cheerio-httpcli/index.js 92 @ ./src/index.ts 93 94ERROR in ./node_modules/require-uncached/node_modules/resolve-from/index.js 95Module not found: Error: Can't resolve 'module' in 'C:\Users\eai\source\repos\clasp\node_modules\require-uncached\node_modules\resolve-from' 96 @ ./node_modules/require-uncached/node_modules/resolve-from/index.js 3:13-30 97 @ ./node_modules/require-uncached/index.js 98 @ ./node_modules/cheerio-httpcli/lib/client.js 99 @ ./node_modules/cheerio-httpcli/lib/core.js 100 @ ./node_modules/cheerio-httpcli/index.js 101 @ ./src/index.ts 102 103ERROR in ./node_modules/forever-agent/index.js 104Module not found: Error: Can't resolve 'net' in 'C:\Users\eai\source\repos\clasp\node_modules\forever-agent' 105 @ ./node_modules/forever-agent/index.js 6:10-24 106 @ ./node_modules/request/request.js 107 @ ./node_modules/request/index.js 108 @ ./node_modules/cheerio-httpcli/lib/client.js 109 @ ./node_modules/cheerio-httpcli/lib/core.js 110 @ ./node_modules/cheerio-httpcli/index.js 111 @ ./src/index.ts 112 113ERROR in ./node_modules/tough-cookie/lib/cookie.js 114Module not found: Error: Can't resolve 'net' in 'C:\Users\eai\source\repos\clasp\node_modules\tough-cookie\lib' 115 @ ./node_modules/tough-cookie/lib/cookie.js 32:10-24 116 @ ./node_modules/cheerio-httpcli/lib/client.js 117 @ ./node_modules/cheerio-httpcli/lib/core.js 118 @ ./node_modules/cheerio-httpcli/index.js 119 @ ./src/index.ts 120 121ERROR in ./node_modules/tunnel-agent/index.js 122Module not found: Error: Can't resolve 'net' in 'C:\Users\eai\source\repos\clasp\node_modules\tunnel-agent' 123 @ ./node_modules/tunnel-agent/index.js 3:10-24 124 @ ./node_modules/request/lib/tunnel.js 125 @ ./node_modules/request/request.js 126 @ ./node_modules/request/index.js 127 @ ./node_modules/cheerio-httpcli/lib/client.js 128 @ ./node_modules/cheerio-httpcli/lib/core.js 129 @ ./node_modules/cheerio-httpcli/index.js 130 @ ./src/index.ts 131 132ERROR in ./node_modules/forever-agent/index.js 133Module not found: Error: Can't resolve 'tls' in 'C:\Users\eai\source\repos\clasp\node_modules\forever-agent' 134 @ ./node_modules/forever-agent/index.js 7:10-24 135 @ ./node_modules/request/request.js 136 @ ./node_modules/request/index.js 137 @ ./node_modules/cheerio-httpcli/lib/client.js 138 @ ./node_modules/cheerio-httpcli/lib/core.js 139 @ ./node_modules/cheerio-httpcli/index.js 140 @ ./src/index.ts 141 142ERROR in ./node_modules/tunnel-agent/index.js 143Module not found: Error: Can't resolve 'tls' in 'C:\Users\eai\source\repos\clasp\node_modules\tunnel-agent' 144 @ ./node_modules/tunnel-agent/index.js 4:10-24 145 @ ./node_modules/request/lib/tunnel.js 146 @ ./node_modules/request/request.js 147 @ ./node_modules/request/index.js 148 @ ./node_modules/cheerio-httpcli/lib/client.js 149 @ ./node_modules/cheerio-httpcli/lib/core.js 150 @ ./node_modules/cheerio-httpcli/index.js 151 @ ./src/index.ts 152

Critical dependency: the request of a dependency is an expression
Module not foundを解決する必要がありそうですが、調べてもわかりませんでした。

この後どうすればビルドできるようになるのでしょうか

環境

  • Windows 7
  • node v8.11.1
  • npm 5.6.0

json

1 "devDependencies": { 2 "@types/google-apps-script": "0.0.21", 3 "@types/jest": "^22.2.0", 4 "cheerio-httpcli": "^0.7.2", 5 "cpx": "^1.5.0", 6 "gas-webpack-plugin": "^0.2.1", 7 "jest": "^22.4.2", 8 "prettier": "^1.11.1", 9 "rimraf": "^2.6.2", 10 "ts-jest": "^22.4.1", 11 "ts-loader": "^4.0.1", 12 "tslint": "^5.9.1", 13 "tslint-config-prettier": "^1.10.0", 14 "tslint-plugin-prettier": "^1.3.0", 15 "typescript": "^2.7.2", 16 "typings": "^2.1.1", 17 "webpack": "^4.1.1", 18 "webpack-cli": "^2.0.12" 19 },

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

エラーの出ているchild_processfsNode.js組み込みのモジュールなので、ブラウザやGASなど、Node.js以外の環境では動きません。

当該のQiita記事のタイトルにもありますように、このcheerio-httpcliNode.js環境で動かす専用です。

投稿2018/04/11 08:12

maisumakun

総合スコア145183

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Eai

2018/04/11 08:19

`cheerio-httpcli`と`cheerio`を同一のものと勘違いしていました……。 普通に`cheerio`をインストールして`require`するのは問題なくできました。ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問