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

Fix "Module parse failed" errors on Windows #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

neeh
Copy link

@neeh neeh commented Apr 24, 2024

I encountered these errors when building on Windows:

  • Module parse failed: Invalid escape sequence
  • Module parse failed: Octal literal in strict mode

It seems to be caused by the backslash characters of Windows paths. Those are treated as either an escape sequence (e.g. \n) or an octal literal (e.g. \345) by JS.

Replacing backslash characters with forward slash characters in the exported file path fixed the issue.

@haversnail haversnail added the good first issue Good for newcomers label May 14, 2024
@haversnail
Copy link
Owner

haversnail commented May 14, 2024

Seems straightforward enough; thanks for fixing!

Edit: after some investigation, it seems a more resilient/conventional way to handle this would be to use the posix object to ensure the correct separators are used, e.g.:

-  const fullPath = path.join(publicPath, interpolatedPath).replace(/\\/g, '/');
+  const fullPath = path.posix.join(publicPath, interpolatedPath);

Can you confirm if this approach also resolves your specific issue? If so, feel free to update the PR to use the posix implementations where path is used and I can approve/merge. 👍

@neeh
Copy link
Author

neeh commented May 16, 2024

I tested your suggestion but this didn't work because the strings to join also have the backslash themselves:

path.join('my\\path', 'to\\model.gltf'); // 'my\\path\\to\\model.gltf'

path.posix.join('my\\path', 'to\\model.gltf'); // 'my\\path/to\\model.gltf'

path.join('my\\path', 'to\\model.gltf').replace(/\\/g, '/'); // 'my/path/to/model.gltf'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants