module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.27k stars 182 forks source link

Spaces in path to project with @module-federation/next-mf result in `Unterminated string in JSON at position` and HookWebpackError errors #2684

Open VityaSchel opened 2 days ago

VityaSchel commented 2 days ago

Describe the bug

I spent 3 hours figuring out why your example https://github.com/module-federation/module-federation-examples/blob/master/nextjs-v14 worked and my project didn't I removed files one by one, making smaller and smaller changes, I though problem was in bun, in node modules cache, in next.js versions difference, until eventually I was left with two identical projects (I even changed .tsx to .js) but in one directory it worked and it another it didn't

Turns out, if I add spaces to the path where project is and where I'm running it, it will fail to compile throwing this long error:

HookWebpackError: Unterminated string in JSON at position 78
    at makeWebpackError (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/webpack/lib/Compilation.js:3181:12
    at eval (eval at create (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:30:1)
-- inner error --
SyntaxError: Unterminated string in JSON at position 78
    at JSON.parse (<anonymous>)
    at ModuleHandler._handleContainerModule (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1079:22)
    at /Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1138:31
    at Array.forEach (<anonymous>)
    at ModuleHandler.collect (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1127:31)
    at /Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1682:72
    at step (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1402:23)
    at Object.next (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1343:20)
    at asyncGeneratorStep$1 (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1165:28)
    at _next (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1183:17)
caused by plugins in Compilation.hooks.processAssets
SyntaxError: Unterminated string in JSON at position 78
    at JSON.parse (<anonymous>)
    at ModuleHandler._handleContainerModule (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1079:22)
    at /Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1138:31
    at Array.forEach (<anonymous>)
    at ModuleHandler.collect (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1127:31)
    at /Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1682:72
    at step (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1402:23)
    at Object.next (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1343:20)
    at asyncGeneratorStep$1 (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1165:28)
    at _next (/Users/hloth/Downloads/module-federation-examples/files fuck me/node_modules/@module-federation/manifest/dist/index.cjs.js:1183:17)

Reproduction

https://github.com/module-federation/module-federation-examples/blob/master/nextjs-v14

Used Package Manager

npm

System Info

N/A

Validations

VityaSchel commented 2 days ago

For your information, I'm running this on macOS, but this shouldn't make any difference because I saw person with the same problem on Windows

ScriptedAlchemy commented 2 days ago

set manifest: false on the plugin for now as workaround

ScriptedAlchemy commented 2 days ago

@VityaSchel example seems to work for me. Supply a repo that reproduces the issue

github-actions[bot] commented 2 days ago

Hello @VityaSchel. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 5 days.

VityaSchel commented 2 days ago

@VityaSchel example seems to work for me. Supply a repo that reproduces the issue

it does not matter which project you take, the problem is in path, you can run empty project with spaces in path to it

ScriptedAlchemy commented 2 days ago

i did and it worked. Supply a repo broken from the start

VityaSchel commented 1 day ago

i did and it worked. Supply a repo broken from the start

example repo with nextjs v14 does not work in my case with bun.sh if you can't reproduce and won't fix this, you can close this, it still will be a starting point for developers who have the same issue