You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My understanding is the file system in pages/ is what defines the routing for the application. Currently it appears to be finding files that has a .js extension. I'm trying to use Next.js in a custom server written entirely in TypeScript and am hitting a wall.
Because Next.js only recognizes .js files in pages/, I cannot use .tsx files even if I add a loader (ts-loader, awesome-typescript-loader) to Webpack via next.config.js.
If I precompile the TypeScript files in pages/ using tsc, it's going to compile files that are shared by both server and pages/. That puts me in a quandary:
If compile the code to be server friendly (ES2015 without import/export and no JSX), I get more verbose code and debugging becomes a pain, plus I assume I lose tree shaking capabilities in Webpack.
If I compile the code to be more up to date as per the examples in the README, I need to use Babel when running my server code and possibly have to fight Next.js' Babel config.
I can't take advantage of tools like ts-node because compiled .js files are picked first over any .ts/.tsx files.
When I write tests for my projects, I like to have them either next to my source files or use Jest's __tests__ neighboring folder. Unfortunately, this presents a problem in the pages/ directory.
I'm thinking that a result it would be nice if next.config.js could have an option that allows one to specify which files in pages/ should get picked up by Next for routing/compilation, which defaults to the current behavior of picking up all .js files. It can be for instance a function that provides as an argument the path of a file in pages/ and returns a boolean to indicate if the file should be processed or excluded. This is my repo/branch I'm playing around trying to get things to work. I'm sure there's other things I'm doing wrong as I'm trying out things via trial and error, but the compilation/extension issue is a roadblock. I figure I would open up an issue for tracking since I've asked around and have heard no answers, which makes sense if everyone is busy.
The text was updated successfully, but these errors were encountered:
Currently it's only .js. It's unlikely, we'll change it on the short term.
And we want to go with the least amount of options as possible we can.
I would suggest you to play with some babel-plugin for this.
My understanding is the file system in
pages/
is what defines the routing for the application. Currently it appears to be finding files that has a.js
extension. I'm trying to use Next.js in a custom server written entirely in TypeScript and am hitting a wall..js
files inpages/
, I cannot use.tsx
files even if I add a loader (ts-loader
,awesome-typescript-loader
) to Webpack vianext.config.js
.pages/
usingtsc
, it's going to compile files that are shared by both server andpages/
. That puts me in a quandary:ts-node
because compiled.js
files are picked first over any.ts
/.tsx
files.__tests__
neighboring folder. Unfortunately, this presents a problem in thepages/
directory.I'm thinking that a result it would be nice if
next.config.js
could have an option that allows one to specify which files inpages/
should get picked up by Next for routing/compilation, which defaults to the current behavior of picking up all.js
files. It can be for instance a function that provides as an argument the path of a file inpages/
and returns a boolean to indicate if the file should be processed or excluded. This is my repo/branch I'm playing around trying to get things to work. I'm sure there's other things I'm doing wrong as I'm trying out things via trial and error, but the compilation/extension issue is a roadblock. I figure I would open up an issue for tracking since I've asked around and have heard no answers, which makes sense if everyone is busy.The text was updated successfully, but these errors were encountered: