代码之家  ›  专栏  ›  技术社区  ›  Anonymous Creator

动态导入typescript时出错

  •  1
  • Anonymous Creator  · 技术社区  · 8 年前

    我收到以下错误。

    ERROR in [at-loader] ./ClientApp/boot.ts:7:23 
        TS1109: Expression expected.
    ERROR in [at-loader] ./ClientApp/boot.ts:7:29 
        TS1134: Variable declaration expected.
    ERROR in [at-loader] ./ClientApp/boot.ts:8:25 
        TS1109: Expression expected.
    ERROR in [at-loader] ./ClientApp/boot.ts:8:31 
        TS1134: Variable declaration expected.
    

    我有以下靴子。ts文件。

    import './css/site.css';
    import 'bootstrap';
    import Vue from 'vue';
    import VueRouter from 'vue-router';
    Vue.use(VueRouter);
    
    const Counter = () => import('./components/counter/counter');
    const FetchData = () => import('./components/fetchdata/fetchdata');
    
    const routes = [
        { path: '/', component: require('./components/home/home.vue.html') },
        { path: '/counter', component: Counter },
        { path: '/fetchdata', component: FetchData }
    ];
    
    new Vue({
        el: '#app-root',
        router: new VueRouter({ mode: 'history', routes: routes }),
        render: h => h(require('./components/app/app.vue.html'))
    });
    

    我的tsconfig。json文件如下所示,。

    {
      "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "experimentalDecorators": true,
        "module": "esnext",
        "moduleResolution": "node",
        "target": "es5",
        "sourceMap": true,
        "skipDefaultLibCheck": true,
        "strict": true,
        "importHelpers": true,
        "lib": [
          "es5",
          "es2015.promise"
      ],
        "types": ["webpack-env"]
      },
      "exclude": [
          "bin",
          "node_modules"
      ]
    }
    

    我想实现以下目标。我正在使用webpack。因此,如果需要,我可以在这里发布。

    https://router.vuejs.org/en/advanced/lazy-loading.html

    1 回复  |  直到 8 年前
        1
  •  2
  •   ethan.roday    8 年前

    只有2.4版以上的Typescript才支持动态导入语法。最可能的修复方法是需要升级Typescript版本。

    使用以下命令更新Typescript的版本:

    npm update --save-dev typescript
    

    或者,如果您使用的是全局安装的版本:

    npm update -g typescript
    

    你可以跑步 npm list typescript (或 npm list -g typescript )然后确保它成功。

    推荐文章