Giter Site home page Giter Site logo

Comments (5)

Zlass avatar Zlass commented on June 8, 2024

I've just run into a similar issue as well. Seems to be caused here:

banner: `require('${
// Is source-map-support installed as project dependency, or linked?
require.resolve('source-map-support').indexOf(process.cwd()) === 0
? // If it's resolvable from the project root, it's a project dependency.
'source-map-support/register'
: // It's not under the project, it's linked via lerna.
require.resolve('source-map-support/register')
}');`,

Looks like the require.resolve('source-map-support/register') is resolved as an absolute path which is breaking when I try to copy the prebuilt bundle into my docker container.

from backpack.

SebastianG77 avatar SebastianG77 commented on June 8, 2024

Hi,

thanks for figuring out the problem source. If you need a quick solution for this, you can follow the solution in this post: #42 (comment)

It would be better to fix this issue directly, but if you adjust the backpack.config.js as described in that post and add the dependency to source-map-support manually, there should be no problems with the dependency and you should still be able to get proper source maps.

from backpack.

Zlass avatar Zlass commented on June 8, 2024

Thanks for the link. Ended up doing something similar, but kept the plugin. I was using yarn workspace <workspace name> run build which starts a process in the workspace's directory so I just overwrote the lerna logic. This is what I ended up adding to my backpack.config.js:

    // Quick fix for source-map-support path resolution
    if (config.plugins[1] && config.plugins[1].options && config.plugins[1].options.banner){
      config.plugins[1] = new webpack.BannerPlugin({
        raw: true,
        entryOnly: false,
        banner:  "require('source-map-support/register');",
      })
    }

from backpack.

SebastianG77 avatar SebastianG77 commented on June 8, 2024

Hi,

I tested your code in my small test project and it worked! Thanks a lot. This solution is better than the other one as I do not need to add source-map-support dependency manually.

Meanwhile I also had a look into the source code and was thinking about how to fix this problem. As mentioned above, aside from the absolute path I also had a problem with missing backslashes. I think there must be an escaping problem somewhere, but I did not figure out where the actual problem occurs as the path itself is built correctly (apart from the fact that it is an absolute one),

Anyway, maybe the problem could be solved by changing the code as depicted in the following:

        banner: `require('${
          // Is source-map-support installed as project dependency, or linked?
          require.resolve('source-map-support').indexOf(process.cwd()) === 0
            ? // If it's resolvable from the project root, it's a project dependency.
              'source-map-support/register'
            : // It's not under the project, it's linked via lerna.
              path.isAbsolute(require.resolve('source-map-support/register'))
              ? 
                process.platform === 'win32'
                ?
                path.relative(config.buildPath, require.resolve('source-map-support/register')).replace(/\\/g,`/`)
                :
                path.relative(config.buildPath, require.resolve('source-map-support/register'))
                :
                process.platform === 'win32'
                ?
                require.resolve('source-map-support/register').replace(/\\/g,`/`)
                :
                require.resolve('source-map-support/register')

        }');

It looks a bit ugly, but this code works for me and should not break anything as on non-Windows OS no backslashes will be replaced. Furthermore, relative paths will only be built if they are absolute ones.

I think I will make a pull request the next days. Will in this context also try to clean up the code a bit.

from backpack.

Zlass avatar Zlass commented on June 8, 2024

Glad I could help! I tried something similar with path.relative but was still having issues with it on macOS. I was also thinking about making a PR, but I'm still in the process of learning Lerna so I'm not positive if it'll break things on that front.

from backpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.