Skip to content
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

Fail to compile when a package name is customised #90

Closed
1 task done
ivawzh opened this issue Jul 3, 2020 · 3 comments
Closed
1 task done

Fail to compile when a package name is customised #90

ivawzh opened this issue Jul 3, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@ivawzh
Copy link

ivawzh commented Jul 3, 2020

  • I HAVE READ THE FAQ AND MY PROBLEM WAS NOT DESCRIBED THERE

Are you trying to transpile a local package or an npm package?
Local package

Describe the bug

When I customize a package name, i.e. name in package.json is different from the package folder name, it fails with error message :

/node_modules/db/index.tsx 1:17
Module parse failed: Unexpected token (1:17)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> const Db = () => <p>DB!</p>
| 
| export default Db

To Reproduce

Reproduction repo here

Home page (without requiring name-customised package) is working

image

The page requires name-customised package is failing

image

When comparing the working and failing pages, apparently the error drivers are from

https://github.com/ivawzh/reproduce-next-transpile-modules-error/blob/0e8af7e8696f858875f39ecc5c6aa613fb9cdcea/packages/web-app/next.config.js#L5

https://github.com/ivawzh/reproduce-next-transpile-modules-error/blob/0e8af7e8696f858875f39ecc5c6aa613fb9cdcea/packages/db/package.json#L2

Expected behavior

I believe (correct me if I am wrong) the correct behaviour is that it doesn't restrict package name to match folder's name, especially when the name is following the yarn workspace's common pattern. If that's not the case, would you please also let me know what kind of implementation the doc was referring to 👇 ?

const withTM = require('next-transpile-modules')(['@shared/ui', '@shared/utils']);

Thanks in advanced 🙂

Setup

  • Next.js version: 9.4.4
  • next-transpile-modules version: 3.3.0
  • Node.js version: v12.16.1
  • npm/yarn version: yarn v1.22.4
  • Operating System: Mac 10.15.5
@martpie
Copy link
Owner

martpie commented Jul 6, 2020

Hello there 👋

I did not think about this case but I am not suprised at all. Webpack (the Next.js bundler) does not really know the exact path of a specified package (we work with regexes in order to detect if we should transpile a package or not).

There is probably a couple of things we could do about it. In the meantime, I highly recommend to use the same name than the pathname (I don't really see a valid usecase when you would like to do that)

@martpie martpie added the enhancement New feature or request label Jul 6, 2020
@ivawzh
Copy link
Author

ivawzh commented Jul 8, 2020

Oh, I see. Just wondering in the doc

const withTM = require('next-transpile-modules')(['@shared/ui', '@shared/utils']);

How do you prepend the namespace to the folder name? As there is a / in the name.

As usecase, it's a common practice to have namespace in monorepo to avoid external package naming collision. It is also easier to identify which dependencies are internal base on the @namespace.

However, it turns out the lib I need requires ts config with module: 'commonjs' which conflicts with NextJS dynamic import. Therefore, I am not able to use next-transpile-modules in the project. Instead, now I am using yarn workspaces + tsc composite + webpack extra file watch plugin.

So please feel free to close the issue if you found it not relevant anymore. Thanks for asking my questions =]

@martpie martpie mentioned this issue Sep 2, 2020
Closed
15 tasks
@martpie
Copy link
Owner

martpie commented Nov 9, 2020

Should be fixed in #132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants