New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files outside of app directory will not be transpiled #5666

Open
Swatinem opened this Issue Nov 13, 2018 · 2 comments

Comments

2 participants
@Swatinem
Copy link

Swatinem commented Nov 13, 2018

Bug report

Describe the bug

I have a monorepo usecase, where I want to share code between the next app and other modules that are located outside of the app folder.

It will end up with this error:

{ Error: (client) ../foo.ts 1:0
Module parse failed: The keyword 'interface' is reserved (1:0)
You may need an appropriate loader to handle this file type.
> interface Foo {
|   prop: string;
| }
 @ ./pages/index.tsx 4:0-28 8:5-8
 @ multi ./pages/index.tsx

To Reproduce

I have set up a simple repo here, based on the next-typescript example:

https://github.com/Swatinem/next-monorepo/tree/master

Expected behavior

Whatever I import should be transpiled like everything else, period.

System information

  • OS: linux
  • Version of Next.js: next@7.0.2

Additional context

Related issue (possibly a duplicate?): zeit/next-plugins#234
Also related maybe:

@timneutkens

This comment has been minimized.

Copy link
Member

timneutkens commented Nov 13, 2018

Sounds like this is a duplicate of #706

@Swatinem

This comment has been minimized.

Copy link

Swatinem commented Nov 14, 2018

Just for reference, this is the extremely ugly workaround I found for this:

    // NOTE(swatinem): we just assume the typescript loader is configured last
    const tsxRules = config.module.rules[config.module.rules.length - 1]

    // By default next-typescript only includes things in the app root for no real reason -_-
    // See: https://github.com/zeit/next-plugins/blob/be21851f63e82845387e576f5f2ed3e5c448cb97/packages/next-typescript/index.js#L51
    // See: https://github.com/zeit/next-plugins/issues/234
    tsxRules.include = undefined

    // Also, apparently babel does not search for the `.babelrc` based on the `root`
    // option correctly when the file to transpile is outside of the root.
    // See: https://babeljs.io/docs/en/options#root
    // So we just pass a path to the babelrc manually here
    defaultLoaders.babel.options.configFile = path.join(__dirname, '.babelrc')

skmdev added a commit to skmdev/koa-next-ts that referenced this issue Dec 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment