B
B
BonBon Slick2020-12-31 16:38:20
JavaScript
BonBon Slick, 2020-12-31 16:38:20

Webpack Unexpected token import/export?

const routerPaths = require('../src/router/public').default; 
/ /unexpected token {, from import inside public.js
import { default as routerPaths } from '../src/router/public'; 
// unexpected token {
import ('../src/router/public'); 
// error, not supported

public.js
Bubble is not in DEV ENV, it is for PROD ENV. Therefore, all the answers that lead to the dough, this is the first page of Google, do not fit, because. you need to register the config for the bubble loader.
import { HOME, SEARCH, VIDEO } from '@/router/urls';

const paths = [
    {
        path:      HOME,
        name:      'home',
        component: () => import('@/components/public/pages/home.vue'),
...

export default paths;
 // ERROR!   Unexpected token export
// export default paths;
   ^^^^^^

{
                test:    /\.vue$/,
                loader:  'vue-loader',
                options: {
                    loaders: {
                        scss: 'vue-style-loader!css-loader!sass-loader', // <style lang="scss">
                        sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax', // <style lang="sass">
                    },
                },
            },
            {
                test:    /\.js$/,
                use:     'source-map-loader',
                exclude: /node_modules/,
            },


// PROD


            {
                test:    /\.js$/,
                use:     'babel-loader',
                exclude: /node_modules/,
            },

The error occurs even if you replace the source map loader with babel.
"babel-core": "^6.26.3",
    "babel-eslint": "^8.2.3",
    "babel-loader": "^7.1.4",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",

    "webpack": "^4.20.2"

https://github.com/babel/babel-loader/issues/493
This package is useless.
"plugins": [
    "transform-runtime",
    "dynamic-import-node",
    "@babel/plugin-syntax-dynamic-import"
  ],

like this one https://babeljs.io/docs/en/babel-plugin-syntax-dyn...
Still the same error...
{
  "presets": [
    [
      "env",
      {
        "modules": false,
        "targets": {
          "browsers": [
            "> 1%",
            "last 2 versions",
            "not ie <= 8"
          ]
        }
      }
    ],
    "stage-2"
  ],
  "plugins": [
    "transform-runtime"
  ],
  "comments": false,
  "env": {
    "test": {
      "presets": [
        "es2015",
        "env",
        "stage-2"
      ],
      "plugins": [
        "istanbul"
      ]
    }
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question