next-multilingual: Moving components into packages of a monorepo breaks the babelifiedMessages

Hi @nbouvrette Nicolas

have you ever done some work in a monorepo?

I have changed our codebase and some of the translated components are moved into a packages folder in second workplace.

If you use inside a component from packages/components:

import { getMessages } from 'next-multilingual/messages';

it will break the main process due to:

function getBabelifiedMessages(sourceFilePath) {
    var parsedSourceFile = path.parse(sourceFilePath);
    var sourceFileDirectoryPath = parsedSourceFile.dir;
...

while sourceFileDirectoryPath is relative (missing root).

I just made a quick fix into the node_modules js file

if (sourceFileDirectoryPath.startsWith('Users/')) sourceFileDirectoryPath = '/' + sourceFileDirectoryPath;

which does the work now on my machine.

I am thinking if a path translator should be added in the plugin configuration like imports from webpack or paths from tsconfig.json

like:

  pluginConfiguration: [
    "next-multilingual/messages/babel-plugin",
    {
      applicationId: appId,
      ...,
      paths: {
        "Users/"; "/Users/"
      }
    }
  ]

or if it just should check if relative path exists and if not try as full path.

Thanks for feedback and hopefully you are fine

Tom

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 29 (15 by maintainers)

Most upvoted comments

@TomFreudenberg I’ll close this issue for now, please ping me on Twitter or open up another discussion if you need anything.

OK cool and I still had a few thing in our backlog that we never got to. Not sure if they would help or not at this point but keep me posted!

Yes, I don’t foresee significant changes any time soon unless we find unexpected bugs with the new version but the +800 tests should have hopefully caught most of them 😃

Great news. Looking forward to try this myself shortly as well