Node appの構築 初期

node.js環境にて下記を参考にアプリの構築テストをしているのですが、うまくいきません。

https://github.com/Shopify/shopify-api-node/blob/main/docs/getting_started.md

※すでにshopifyにてtestappは構築済み

// src/index.ts
import http from 'http';
import url from 'url';
import querystring from 'querystring';
import Shopify, { ApiVersion } from '@shopify/shopify-api';
require('dotenv').config();

const { API_KEY, API_SECRET_KEY, SCOPES, SHOP, HOST, HOST_SCHEME } = process.env;

Shopify.Context.initialize({
  API_KEY,
  API_SECRET_KEY,
  SCOPES: [SCOPES],
  HOST_NAME: HOST.replace(/https?:\/\//, ""),
  HOST_SCHEME,
  IS_EMBEDDED_APP: {boolean},
  API_VERSION: ApiVersion.{version} // all supported versions are available, as well as "unstable" and "unversioned"
});

// Storing the currently active shops in memory will force them to re-login when your server restarts. You should
// persist this object in your app.
const ACTIVE_SHOPIFY_SHOPS: { [key: string]: string | undefined } = {};

参考通り上記を置いてyarn startをしてみたのですが、

src/index.ts:2:1 - error TS6133: 'http' is declared but its value is never read.

2 import http from 'http';
  ~~~~~~~~~~~~~~~~~~~~~~~~

src/index.ts:3:1 - error TS6133: 'url' is declared but its value is never read.

3 import url from 'url';
  ~~~~~~~~~~~~~~~~~~~~~~

src/index.ts:4:1 - error TS6133: 'querystring' is declared but its value is never read.

4 import querystring from 'querystring';

まずは上記のエラーが出ます。

しらべたところとくにnode_moduleの初期に入っているモジュールなので何もしなくていいとみつけたのですが、どうすれば解決できますでしょうか?

@cheche0830

こんにちは!

上記githubのリポジトリにあるファイルは全て揃っておりますでしょうか?

https://github.com/Shopify/shopify-api-node)

全て揃っていないのであれば、揃えてください。

その後、インストールコマンドを動作させてください。

yarn install

正常にインストールが完了すればnode_modulesが作成されているはずです。

その状態で yarn start してください。

解決になりましたら幸いです。よろしくお願いします!

ご返信ありがとうございます!こちらになります!

{
  "name": "@shopify/shopify-api",
  "version": "5.0.1",
  "description": "Shopify API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "prettier": "@shopify/prettier-config",
  "scripts": {
    "test": "jest --testPathIgnorePatterns=src/rest-resources/__tests__ --testPathIgnorePatterns=src/auth/session/storage",
    "test_sessionstorage": "jest src/auth/session/storage",
    "test_rest_resources": "ls src/rest-resources/__tests__ | xargs -I \"{}\" sh -c 'yarn jest --no-coverage --testPathPattern=\\\"{}\\\" || exit 255'",
    "build": "npx tsc",
    "prestart": "yarn run build",
    "start": "node dist/index.js",
    "lint": "eslint '**/*.{ts,tsx}' --max-warnings 0",
    "clean": "rimraf ./dist tsconfig.tsbuildinfo",
    "prepublishOnly": "yarn run build",
    "preversion": "yarn run test",
    "postversion": "git push origin main --follow-tags && echo \"Log in to shipit to deploy version $npm_package_version\""
  },
  "publishConfig": {
    "access": "public"
  },
  "repository": "git+https://github.com/Shopify/shopify-api-node.git",
  "bugs": {
    "url": "https://github.com/Shopify/shopify-api-node/issues"
  },
  "homepage": "https://github.com/Shopify/shopify-api-node",
  "author": "Shopify Inc.",
  "license": "MIT",
  "keywords": [
    "shopify",
    "node",
    "jwt",
    "app",
    "graphql",
    "rest",
    "webhook",
    "Admin API",
    "Storefront API"
  ],
  "resolutions": {
    "node-fetch": "^2.6.7"
  },
  "dependencies": {
    "@shopify/network": "^1.5.1",
    "@shopify/shopify-api": "^5.0.1",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/node-fetch": "^2.5.7",
    "@types/supertest": "^2.0.10",
    "cookies": "^0.8.0",
    "jsonwebtoken": "^8.5.1",
    "mongodb": "^4.5.0",
    "mysql2": "^2.3.3",
    "node-fetch": "^2.6.1",
    "pg": "^8.7.3",
    "redis": "^4.0.6",
    "sqlite3": "^5.0.8",
    "tslib": "^2.0.3",
    "uuid": "^8.3.1"
  },
  "devDependencies": {
    "@shopify/eslint-plugin": "^41.1.0",
    "@shopify/prettier-config": "^1.1.2",
    "@types/cookies": "^0.7.5",
    "@types/jest": "^26.0.15",
    "@types/node": "^18.6.3",
    "@types/pg": "^8.6.5",
    "@types/sqlite3": "^3.1.8",
    "@types/uuid": "^8.3.0",
    "dotenv": "^16.0.1",
    "eslint": "^7.30.0",
    "eslint-plugin-prettier": "^4.0.0",
    "express": "^4.17.1",
    "jest": "^27.4.3",
    "jest-fetch-mock": "^3.0.3",
    "prettier": "^2.5.1",
    "rimraf": "^3.0.2",
    "supertest": "^6.1.3",
    "ts-jest": "^27.1.1",
    "typescript": "^4.7.4"
  },
  "files": [
    "dist/*",
    "!tsconfig.tsbuildinfo"
  ]
}

Cheche0830 様

横から失礼いたします。

「‘xxx’ is declared but its value is never read.」

こちらのエラーはTypescriptのコンパイルエラーではないでしょうか。

(モジュールをimportしたけど使ってないよ、と言ってくれているのかと)

解決法としては、

①ファイル最上部に* @TS -nocheck*を記述する。

②該当モジュールに* @TS -ignore*を記述する。

③tsconfig.jsonのnoUnusedParametersfalseにする。

※フォーラムの仕様で大文字になりますが、ts-nocheckとts-ignoreはすべて小文字です。

(参考資料)

https://blog.ojisan.io/eslint-ts-ignore/#%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%8D%98%E4%BD%8D%E3%81%A7%E7%84%A1%E8%A6%96%E3%81%99%E3%82%8B

②③https://qiita.com/Ryusou/items/c7d28b39c4d1214e0410

ご参考になれば幸いです。

株式会社フルバランス ドウケ

ありがとうございました!試してみたのですが変わらずでした。。

なるほどですね。。いったん、本筋とは関係なさそうなので削除したら進めました。ありがとうございました!別の問題が出ましたので新しいスレッド立てさせていただきます!