question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better support for `type: "module"` from user

See original GitHub issue

Is your feature request related to a problem? Please describe.

The outputs ESM entries are not fully compatible with native ESM actually, take the following as example

https://unpkg.com/browse/vitepress@1.0.0-alpha.4/dist/client/index.js

All relative file paths should be ended with correct .js extension, and /index.js can not be omitted anymore.

That’s being said, we should use moduleResolution: "Node16" instead.

And when the user enables type: "module" in their package.json or .vitepress/package.json, all temporary .js files in .vitepress/.temp would be considered as ESM only, and now it would emit error:

vitepress v1.0.0-alpha.4
- building client + server bundles...
@alauda/chart doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
quill-image-uploader doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
✓ building client + server bundles...
- rendering pages...
✖ rendering pages...
build error:
 ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/jenkins/agent/workspace/frontend/frontend-vision-docs/docs/.vitepress/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/docs/.vitepress/.temp/app.js:2:25
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async renderPage (file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/node_modules/vitepress/dist/node/serve-05342c3d.js:39534:25)
    at async build (file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/node_modules/vitepress/dist/node/serve-05342c3d.js:39853:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
script returned exit code 1

Describe the solution you’d like

Enable moduleResolution: "Node16" and add a package.json into .vitepress/.temp with type: "commonjs" for now, and migrate all outputs files as pure ESM later.

Describe alternatives you’ve considered

We can use .cjs files extensions for files outputs in .vitepress/.temp

Additional context

Reference https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:22 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
JounQincommented, Aug 7, 2022
1reaction
JounQincommented, Aug 5, 2022

OK, I’ll add it locally and manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript modules via script tag | Can I use... Support tables ...
Loading JavaScript module scripts (aka ES6 modules) using <script type="module"> Includes support for the nomodule attribute. Usage % of. all users, all tracked ......
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
Modules, introduction - The Modern JavaScript Tutorial
A module is a file. To make import/export work, browsers need <script type="module"> . · Modules have their own, local top-level scope and ......
Read more >
Why is 'type: module' in package.json file? - Stack Overflow
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: │ │ ~~/nuxt.config.js │ │ require() of ES modules is not supported. │ │ ......
Read more >
CommonJS vs. ES modules in Node.js - LogRocket Blog
Over 200k developers use LogRocket to create better digital experiences · Node.js support for ES modules · More great articles from LogRocket:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found