I would like to test out building out a shopify app using Typescript by starting with the shopify-app-cli boilerplate, which uses Koa as a server and Nextjs for the front end react javascript.
see https://github.com/Shopify/shopify-app-cli
I am having trouble getting the typescript code compiling for both the server and the nextjs frontend code.
Changes:
-
All of the file extensions to be either
.tsx
or.ts
. instead of.js
-
In package.json, changed “dev” script to use ts-node instead of using
nodemon
before
"dev": "NODE_ENV=development nodemon ./server/index.js --watch ./server/index.js",
after
"dev": "NODE_ENV=development ts-node server/server.ts",
I can get it to compile the server.ts
file, however if i change the nextjs files pages/_app.js
and pages/index.js
to .tsx
it can’t find them and has this error:
[ event ] client pings, but there's no entry for page: /
This is the tsconfig.json
file have set up.
{
"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"]
}
also a gist of server.ts
, https://gist.github.com/azrielh/73ac202fcce5ce32f19488e4ef5df263.js
2
Answers
I got it to work with basically the setup that you describe.
It all runs, compiles, and sees the TSX pages as expected.
Here’s my package.json:
Here’s an updated answer for CLI 3.x. This only applies to
web/frontend
.tsconfig.json
with the following.dev
&build
scripts in thepackage.json
. Fordev
we will run our TypeScript compiler in watch mode. Forbuild
, we can check types once before building.Shopify uses Vite under the hood which only performs transpilation on
.ts
files and does NOT perform type checking. This means you’ll have to lean on your IDE to point out any compilation errors as the build will still pass.In-depth steps including adding eslint & prettier can be found here.