Search code examples
vue.jsvuejs2pinia

can't import the named export 'computed' from non ecmascript module pinia and Vue 2


After installing Pinia on my Vue 2 project, and imported it in the main.js file I got this error

Failed to compile.

./node_modules/pinia/dist/pinia.mjs 1147:44-52
Can't import the named export 'computed' from non EcmaScript module (only default export is available)

Solution

  • This Vue configuration should do the trick

    // vue.config.js
    module.exports = {
      configureWebpack: {
        module: {
          rules: [
            {
              test: /\.mjs$/,
              include: /node_modules/,
              type: "javascript/auto"
            }
          ] 
        }
      }
    }
    

    As mentioned in this Github issue.