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.

Error when using Vite (Vue 3)

See original GitHub issue

Expected Behavior

There is an error running applications using Vite (https://github.com/vitejs/vite). After installing the dependency using yarn add contentful and then running yarn dev, the server should start normally but fails with an error.

Actual Behavior

Running yarn dev will cause the server to error with the following error:

[vite] Dep optimization failed with error:
'platform' is not exported by node-resolve:empty.js, imported by node_modules/contentful-sdk-core/dist/index.es-modules.js
Error: 'platform' is not exported by node-resolve:empty.js, imported by node_modules/contentful-sdk-core/dist/index.es-modules.js
    at error (<project dir>/node_modules/rollup/dist/shared/rollup.js:5231:30)
    at Module.error (<project dir>/node_modules/rollup/dist/shared/rollup.js:9787:16)
    at handleMissingExport (<project dir>/node_modules/rollup/dist/shared/rollup.js:9676:28)
    at Module.traceVariable (<project dir>/node_modules/rollup/dist/shared/rollup.js:10177:24)
    at ModuleScope.findVariable (<project dir>/node_modules/rollup/dist/shared/rollup.js:8708:39)
    at FunctionScope.findVariable (<project dir>/node_modules/rollup/dist/shared/rollup.js:2781:38)
    at ChildScope.findVariable (<project dir>/node_modules/rollup/dist/shared/rollup.js:2781:38)
    at Identifier$1.bind (<project dir>/node_modules/rollup/dist/shared/rollup.js:4137:40)
    at CallExpression$1.bind (<project dir>/node_modules/rollup/dist/shared/rollup.js:2867:23)
    at CallExpression$1.bind (<project dir>/node_modules/rollup/dist/shared/rollup.js:6605:15) {
  code: 'MISSING_EXPORT',
  url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module',
  id: '<project dir>/node_modules/contentful-sdk-core/dist/index.es-modules.js',
  pos: 122,
  loc: {
    file: '<project dir>/node_modules/contentful-sdk-core/dist/index.es-modules.js',
    line: 4,
    column: 9
  },
  frame: "2: import qs from 'qs';\n" +
    "3: import isPlainObject from 'lodash/isPlainObject';\n" +
    "4: import { platform, release } from 'os';\n" +
    '            ^\n' +
    '5: \n' +
    '6: function _defineProperty(obj, key, value) {',
   <watch section omitted>

Possible Solution

The error directs you to the following page: https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module

Steps to Reproduce

  1. yarn create vite-app someproject
  2. cd someproject
  3. yarn add contentful
  4. yarn install
  5. yarn dev

Context

Vite seems to be (?) the recommended CLI tool for Vue 3 development. We are having trouble proting our app to vue 3 due to this error.

Environment

  • Vite: v1.0.0-rc.4
  • Vue: v3.0.0
  • Language Version: v14.5.0
  • Package Manager Version: yarn 1.22.4
  • Operating System: Linux 64 bit (Ubuntu 20.04)
  • Package Version: 7.14.8

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
princedcommented, Feb 26, 2021

A workaround for now:

export default defineConfig({
  resolve: {
    alias: {
      // https://github.com/contentful/contentful-sdk-core/issues/58#issuecomment-675052926
      contentful: 'contentful/dist/contentful.browser',
    },
  },
  // ...
});
1reaction
princedcommented, Sep 27, 2021

I’ve just updated to 9.0.0, works like a charm. Thank you @marcolink!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting
Syntax Error / Type Error happens​​ Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This...
Read more >
Vue3 + Vite: error handling in production
But when I use this code in production, the code gets bundled (using Vite) and then the error handling is not useful anymore....
Read more >
Error when running test with vitest + vue3 + vite on ...
Hello,. I'm seeing the following error when running a unit test on a custom component that has a Syncfusion Dialog inside it. Error:....
Read more >
Building a Vue3 Typescript Environment with Vite - miyauci.me
Building a Typescript Vue3 environment using the No bundle tool Vite, along with ESLint and Prettier configuration to create a high DX environment....
Read more >
[Solved]-getting error on vite build in vue3 vite project-Vue.js
In some npm packages, I have used in my project have some features were added from the latest EcmaScript. Like async generator functions,...
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