jaredpalmer / razzle

✨ Create server-rendered universal JavaScript applications with no configuration

Home Page:https://razzlejs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeScript doesn't seem to work outside of src folder

mbzr opened this issue · comments

commented

🐛 Bug report

Using the with-typescript example, I have a config.ts file outside of the src folder. When i import this file inside of src/index.ts file, ts checker fails with error:

Module parse failed: Unexpected token (1:17)\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

Is there any way to make this work?

Reproducible example

https://github.com/MahmoodBawazir/razzle-with-typescript

Your environment

Software Version(s)
Razzle 4.2.15
Razzle Plugins none
Node 16.3.0
Browser chrome
npm/Yarn yarn
Operating System mac
TypeScript ^4.0.3
React ^17.0.1

tried include in tsconfig?

commented

@fivethreeo i did try include. Also tried the other typescript example, played with the tsLoader options, nothing seems to work.

try setting basedir in compileroptions to .

commented

looks like razzle doesnt allow anything other than src for baseUrl. and tried setting rootDir to . didn't work either)

commented

https://codesandbox.io/s/interesting-lederberg-oxi2lc - heres the link for codesandbox i am playing with

commented

Thank you @fivethreeo! adding this to razzle.config.js worked:

module.exports = {
  modifyWebpackOptions({
    env: {
      target, // the target 'node' or 'web'
      dev, // is this a development build? true or false
    },
    options: {
      webpackOptions, // the default options that will be used to configure webpack/ webpack loaders and plugins
    }
  }) {
    webpackOptions.babelRule.include = webpackOptions.babelRule.include.concat([
      /config/
    ]);
    return webpackOptions;
  }
}