如何解决依赖项中检测到的打字稿无法访问的代码

时间:2016-09-16 02:20:21

标签: typescript webpack aurelia

我目前正在收到这些错误

ERROR in [default] /pipeline/source/node_modules/selenium-webdriver/node_modules/adm-zip/zipEntry.js:64:16 
Unreachable code detected.

ERROR in [default] /pipeline/source/node_modules/selenium-webdriver/node_modules/adm-zip/zipEntry.js:110:20 
Unreachable code detected.

这是将其拉进去的代表。

+-- protractor@4.0.8
| +-- @types/node@6.0.38
| +-- @types/q@0.0.30
| +-- adm-zip@0.4.7
| +-- glob@7.0.6
| | `-- minimatch@3.0.3
| +-- jasmine@2.4.1
| | +-- exit@0.1.2
| | +-- glob@3.2.11
| | `-- jasmine-core@2.4.1
| +-- jasminewd2@0.0.10
| +-- q@1.4.1
| +-- saucelabs@1.3.0
| | `-- https-proxy-agent@1.0.0
| |   `-- agent-base@2.0.1
| |     `-- semver@5.0.3
| +-- selenium-webdriver@2.53.3
| | +-- adm-zip@0.4.4
| | +-- tmp@0.0.24
| | +-- ws@1.0.1
| | | +-- options@0.0.6
| | | `-- ultron@1.0.2

我的tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",
    "module": "es2015",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "allowJs": true
  },
  "awesomeTypescriptLoaderOptions": {
    "doTypeCheck": true,
    "forkChecker": true,
    "useBabel": true,
    "useCache": true,
    "babelOptions": {
      "presets": ["es2015-loose-native-modules"]
    }
  },
  "exclude": [
    "node_modules",
    "dist",
    "release",
    "index.js",
    "webpack.config.js",
    "config"
  ]
}

webpack.config.js

"use strict";

/**
 * To learn more about how to use Easy Webpack
 * Take a look at the README here: https://github.com/easy-webpack/core
 **/
const easyWebpack = require( '@easy-webpack/core' );
const generateConfig = easyWebpack.default;
const get = easyWebpack.get;
const path = require( 'path' );
const ENV = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() || 'development';
var config;

// basic configuration:
const title = 'RPF';
const baseUrl = '/';
const rootDir = path.resolve();
const srcDir = path.resolve( 'src' );
const outDir = path.resolve( 'dist' );

const coreBundles = {
    bootstrap: [
        'aurelia-bootstrapper-webpack',
        'aurelia-polyfills',
        'aurelia-pal',
        'aurelia-pal-browser',
        'regenerator-runtime',
        'bluebird'
    ],
    // these will be included in the 'aurelia' bundle (except for the above bootstrap packages)
    aurelia: [
        'aurelia-bootstrapper-webpack',
        'aurelia-binding',
        'aurelia-dependency-injection',
        'aurelia-event-aggregator',
        'aurelia-framework',
        'aurelia-history',
        'aurelia-history-browser',
        'aurelia-loader',
        'aurelia-loader-webpack',
        'aurelia-logging',
        'aurelia-logging-console',
        'aurelia-metadata',
        'aurelia-pal',
        'aurelia-pal-browser',
        'aurelia-path',
        'aurelia-polyfills',
        'aurelia-route-recognizer',
        'aurelia-router',
        'aurelia-task-queue',
        'aurelia-templating',
        'aurelia-templating-binding',
        'aurelia-templating-router',
        'aurelia-templating-resources',
    ]
};

const baseConfig = {
    entry: {
        'app': [ /* this is filled by the aurelia-webpack-plugin */ ],
        'aurelia-bootstrap': coreBundles.bootstrap,
        'aurelia': coreBundles.aurelia.filter( function ( pkg ) {
            return coreBundles.bootstrap.indexOf( pkg ) === -1
        } )
    },
    output: {
        path: outDir
    }
};

// advanced configuration:
switch ( ENV ) {
    case 'production':
        config = generateConfig(
            baseConfig,

            require( '@easy-webpack/config-env-production' )
            ( { compress: true } ),

            require( '@easy-webpack/config-aurelia' )
            ( { root: rootDir, src: srcDir, title: title, baseUrl: baseUrl } ),

            require( '@easy-webpack/config-tslint' )
            ( { emitErrors: true, failOnHint: true } ),
            require( '@easy-webpack/config-typescript' )(),
            require( '@easy-webpack/config-html' )(),

            require( '@easy-webpack/config-css' )
            ( { filename: 'styles.css', allChunks: true, sourceMap: false } ),

            require( '@easy-webpack/config-fonts-and-images' )(),
            require( '@easy-webpack/config-global-bluebird' )(),
            require( '@easy-webpack/config-global-jquery' )(),
            require( '@easy-webpack/config-global-regenerator' )(),
            require( '@easy-webpack/config-generate-index-html' )
            ( { minify: true } ),

            require( '@easy-webpack/config-common-chunks-simple' )
            ( { appChunkName: 'app', firstChunk: 'aurelia-bootstrap' } ),

            require( '@easy-webpack/config-copy-files' )
            ( { patterns: [ { from: 'favicon.ico', to: 'favicon.ico' } ] } ),

            require( '@easy-webpack/config-uglify' )
            ( { debug: false } )
        );
        break;
... // test/dev configs

我知道有一个编译器选项来禁用无法访问的代码,但我不想全局禁用它,而只是为了node_modules中的内容。

1 个答案:

答案 0 :(得分:1)

  

" allowJs":true

我通过发送拉取请求https://github.com/Semantic-Org/Semantic-UI/pull/4225

来解决这个问题

关闭了allowJs(我已经练习了最快1天的迁移:https://www.youtube.com/watch?v=gmKXXI_ck7w)。初学者应该能在一周内完成。它值得。

您还可以尝试exclude node_moduleshttps://basarat.gitbooks.io/typescript/content/docs/project/files.html