Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): expose underlying import errors #1696

Merged
merged 2 commits into from
Nov 4, 2021
Merged

fix(vite): expose underlying import errors #1696

merged 2 commits into from
Nov 4, 2021

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

See nuxt/nuxt#11996

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The current error message when loading externals is:

(node:31884) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Unexpected token 'export'
  at wrapSafe (internal/modules/cjs/loader.js:1001:16)  
  at Module._compile (internal/modules/cjs/loader.js:1049:27)  
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)  
  at Module.load (internal/modules/cjs/loader.js:950:32)  
  at Function.Module._load (internal/modules/cjs/loader.js:790:14)  
  at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)  
  at ModuleJob.run (internal/modules/esm/module_job.js:169:25)  
  at async Loader.import (internal/modules/esm/loader.js:177:24)  
  at async __instantiateModule__ (file://./playground/.nuxt/dist/server/server.mjs:7515:3)

This doesn't reveal anything about the underlying cause or package, and can be very confusing.

This PR changes the logging to the following:

(node:33676) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/v-tooltip/node_modules/@popperjs/core/lib/enums.js:1
export var top = 'top';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async __instantiateModule__ (file:///Users/daniel/code/nuxt/framework/playground/.nuxt/dist/server/server.mjs:7515:3)

Error loading external "/v-tooltip/node_modules/@popperjs/core/lib/enums.js".
  at file://./playground/.nuxt/dist/server/server.mjs:3704:283  
  at async __instantiateModule__ (file://./playground/.nuxt/dist/server/server.mjs:7515:3)

And the message displayed in the browser is, which is more relevant:

Error loading external "/v-tooltip/node_modules/@popperjs/core/lib/enums.js".
  at file://./playground/.nuxt/dist/server/server.mjs:3704:283  
  at async __instantiateModule__ (file://./playground/.nuxt/dist/server/server.mjs:7515:3)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe requested a review from pi0 November 4, 2021 13:54
@danielroe danielroe self-assigned this Nov 4, 2021
@netlify
Copy link

netlify bot commented Nov 4, 2021

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: add1284

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/618423eee8a2510008a71187

@pi0 pi0 merged commit 6f1f12a into main Nov 4, 2021
@pi0 pi0 deleted the fix/expose-esm-error branch November 4, 2021 18:18
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants