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

CommonJS module import failure when module.exports has key containing escaped whitespace #27422

Closed
jceb opened this issue Dec 19, 2024 · 2 comments · Fixed by #27438
Closed
Assignees
Labels
bug Something isn't working correctly

Comments

@jceb
Copy link

jceb commented Dec 19, 2024

Version: Deno 2.1.4

I ran into an issue related to CommonJS modules that hit me while working with https://daisyui.com via this package: @matthiesenxyz/unocss-preset-daisyui / github. When I import a module that exports an object with a \n inside a key, an error is thrown. The same is true for \t and \r. When I put the same code in an ESM module it works without issues.

Test script that imports two scripts, works.js is the ESM module, bang.cjs the CommonJS module.

test.js:

const works = await import("./works.js");
console.log("imported:", works);
const bang = await import("./bang.cjs");
console.log("imported:", bang);

works.js:

export default {
  "\nx": "test",
};

bang.cjs:

module.exports = {
  "\nx": "test",
};

Result:

deno -A test.js
imported: [Module: null prototype] { default: { "\nx": "test" } }
error: Uncaught (in promise) SyntaxError: Invalid or unexpected token at file:///.../bang.cjs:9:31
const bang = await import("./bang.cjs");
          ^
    at async file:///.../bang.js:3:11
@dsherret dsherret added the needs info needs further information to be properly triaged label Dec 19, 2024
@dsherret
Copy link
Member

dsherret commented Dec 19, 2024

Can you try out your reproduction code in a fresh empty folder with no configuration files? I'm not able to reproduce.

Also, is the file called bang.cjs or bang.js? It seems in the output the error is happneing in bang.js (which I'm guessing is actually test.js?)

@jceb
Copy link
Author

jceb commented Dec 20, 2024

Oh, I'm sorry, bang.cjs contained the wrong content. I corrected the mistake and the error should now be reproducible.

@dsherret dsherret added bug Something isn't working correctly and removed needs info needs further information to be properly triaged labels Dec 20, 2024
@dsherret dsherret changed the title CommonJS module import failure CommonJS module import failure when module.exports has key containing escaped whitespace Dec 20, 2024
@dsherret dsherret self-assigned this Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants