【发布时间】:2020-06-04 20:50:41
【问题描述】:
我想通过使用 shopify-app-cli 样板文件来测试使用 Typescript 构建一个 shopify 应用程序,该样板文件使用 Koa 作为服务器,使用 Nextjs 作为前端 react javascript。
见https://github.com/Shopify/shopify-app-cli
我无法为服务器和 nextjs 前端代码编译 typescript 代码。
变化:
所有文件扩展名都是
.tsx或.ts。而不是.js在 package.json 中,将“dev”脚本更改为使用 ts-node 而不是使用
nodemon
之前
"dev": "NODE_ENV=development nodemon ./server/index.js --watch ./server/index.js",
之后
"dev": "NODE_ENV=development ts-node server/server.ts",
我可以让它编译 server.ts 文件,但是如果我将 nextjs 文件 pages/_app.js 和 pages/index.js 更改为 .tsx 它找不到它们并出现此错误:
[ event ] client pings, but there's no entry for page: /
这是已设置的tsconfig.json 文件。
{
"compilerOptions": {
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react"
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
也是server.ts、https://gist.github.com/azrielh/73ac202fcce5ce32f19488e4ef5df263.js的要点
【问题讨论】:
-
你解决了这个@Azhop吗?
标签: typescript shopify next.js koa