Error Cannot find module 'typescript'

14 min read
(node:12418) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module 'typescript'
Require stack:
- /Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/util.js
- /Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/index.js
- /Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/esm.js
- /Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/esm.mjs
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at projectLocalResolveHelper (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/util.js:117:24)
    at resolveCompiler (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/configuration.js:232:22)
    at resolveAndLoadCompiler (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/configuration.js:225:26)
    at findAndReadConfig (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/configuration.js:48:28)
    at create (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/index.js:146:69)
    at register (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/index.js:127:19)
    at Object.registerAndCreateEsmHooks (/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/esm.js:25:49)
    at file:///Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/esm.mjs:8:7 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/util.js',
    '/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/index.js',
    '/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/dist/esm.js',
    '/Users/pan/wechat-chatgpt/node_modules/.pnpm/[email protected]/node_modules/ts-node/esm.mjs'
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

upgrade your node version to 18 nvm install 18& nvm use 18

then npm installtypescript && rm -rf node_modules