typescript:error TS2693:'Promise'只引用一个类型,但在这里被用作值

时间:2017-03-30 13:22:01

标签: javascript typescript promise

我正在尝试使用Typescript作为我的AWS Lambda,我在使用promises时遇到以下错误。

error TS2693: 'Promise' only refers to a type, but is being used as a value here.

我尝试在代码中使用以下变体

使用Promise构造函数

responsePromise = new Promise((resolve, reject) => {
                    return reject(new Error(`missing is needed data`))
                })

使用Promise.reject

responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));

版本

以下是我的开发依赖项中的版本:

"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",

tsconfig.json的内容

{
    "compileOnSave": true,
    "compilerOptions": {
        "module": "commonjs",
        // "typeRoots" : ["./typings", "./node_modules/@types"],
        "target": "es5",
        // "types" : [ "core-js" ],
        "noImplicitAny": true,
        "strictNullChecks": true,
        "allowJs": true,
        "noEmit": true,
        "alwaysStrict": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "outDir": "dist",
        "moduleResolution": "Node",
        "declaration": true,
        "lib": [
            "es6"
        ]
    },
    "include": [
        "index.ts",
        "lib/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

我正在使用具有以下配置的grunt-ts来运行ts任务。

ts: {
            app: {
                tsconfig: {
                    tsconfig: "./tsconfig.json",
                    ignoreSettings: true
                }
            },
...

我尝试了I get: [ts] 'Promise' only refers to a type, but is being used as a value here中提到的解决方案,但没有运气。

23 个答案:

答案 0 :(得分:109)

我对aws-sdk遇到了同样的问题,我使用"target": "es2015"解决了这个问题。这是我的tsconfig.json文件。

{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": false,
        "noImplicitAny": false,
        "module": "commonjs",
        "target": "es2015"
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

答案 1 :(得分:74)

今天遇到同样的错误并用以下方法解决:

npm i --save-dev  @types/es6-promise

<强>更新

添加:

import {Promise} from 'es6-promise'

答案 2 :(得分:32)

我通过在tsconfig.json文件中添加以下代码来解决这个问题。

"lib": [
    "ES5",
    "ES2015",
    "DOM",
    "ScriptHost"]

答案 3 :(得分:18)

通过更改compilerOptions中的目标来解决。

{
"compilerOptions": {
    "module": "es2015",
    "target": "es2015",
    "lib": [
        "es2016",
        "dom"
    ],
    "moduleResolution": "node",
    "noImplicitAny": false,
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "./public/js/app"
},
"exclude": [
    "node_modules",
    "public/js",
    "assets/app/polyfills.ts"
],
"angularCompilerOptions": {
    "skipMetadataEmit": true
}
}

答案 4 :(得分:10)

这是我的提示。使用vscode 1.21.1(在MAC上)进行测试

将以下配置添加到 tsconfig.json

"lib": [
"es2016",
"dom"
]

成 的 compilerOptions

重启IDE(需要执行此操作:D)

答案 5 :(得分:7)

将以下行添加到文件中引发错误。这应解决问题

declare var Promise: any;

答案 6 :(得分:4)

最后tsc开始工作没有任何错误。但是有多重变化。感谢Sandro KeilPointy&amp; unional

  • 删除了dt~aws-lambda
  • 删除了noEmit,声明
  • 等选项
  • 修改了Gruntfile并删除了ignoreSettings

tsconfig.json

{
    "compileOnSave": true,
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "strictNullChecks": true,
        "alwaysStrict": true,
        "preserveConstEnums": true,
        "sourceMap": false,
        "moduleResolution": "Node",
        "lib": [
            "dom",
            "es2015",
            "es5",
            "es6"
        ]
    },
    "include": [
        "*",
        "src/**/*"
    ],
    "exclude": [
        "./node_modules"
    ]
}

Gruntfile.js

ts: {
            app: {
                tsconfig: {
                    tsconfig: "./tsconfig.json"
                }
            },
...

答案 7 :(得分:4)

与打字稿和aws-sdk有同样的问题。解决方法是将目标更改为es6

我的完整tsconfig.json文件:

{
        compilerOptions: {
                outDir: ./dist/,
                sourceMap: true,
                noImplicitAny: true,
                module: commonjs,
                target: es6,
                jsx: react,
                allowJs: true
        },
        include: [
                ./src/**/*
    ]
}

答案 8 :(得分:3)

我遇到了这个错误,但是我使用此命令解决了,我的ts文件名为promises-fs.ts:

tsc promises-fs.ts --target es6 && node promises-fs.js

错误消失了

答案 9 :(得分:2)

在在typeScript 3.0.1中添加以下lib数组之前,我遇到了同样的问题

Undefined symbols for architecture x86_64: "cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from: _main in main.cpp.o "dlib::entropy_decoder_kernel_2::set_stream(std::basic_istream<char, std::char_traits<char> >&)", referenced from: dlib::get_serialized_frontal_faces[abi:cxx11]() in libPoseExprLib.a(DlibWrapper.cpp.o) "H5::H5Location::openDataSet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const", referenced from: readH5Dataset(H5::H5File const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libPoseExprLib.a(BaselFace.cpp.o) "H5::Exception::getDetailMsg[abi:cxx11]() const", referenced from: BaselFace::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [clone .cold.29] in libPoseExprLib.a(BaselFace.cpp.o) "dlib::base64::decode(std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&) const", referenced from: dlib::get_serialized_frontal_faces[abi:cxx11]() in libPoseExprLib.a(DlibWrapper.cpp.o) "std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from: std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str() const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ios_base::getloc() const", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::resize(unsigned long, char)", referenced from: std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::push_back(char)", referenced from: std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from: dlib::error::error(dlib::error_type, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libdlib.a(base64_kernel_1.cpp.o) dlib::error::error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from: std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char)", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush()", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()", referenced from: construction vtable for std::__1::basic_ostream<char, std::__1::char_traits<char> >-in-std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()", referenced from: construction vtable for std::__1::basic_ostream<char, std::__1::char_traits<char> >-in-std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) virtual thunk to std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) virtual thunk to std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(int)", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::sync()", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::imbue(std::__1::locale const&)", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::uflow()", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::setbuf(char*, long)", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::xsgetn(char*, long)", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::xsputn(char const*, long)", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::showmanyc()", referenced from: vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::basic_streambuf()", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) virtual thunk to std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) virtual thunk to std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_stringbuf() in libdlib.a(base64_kernel_1.cpp.o) ... "std::__1::iostream_category()", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::cerr", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ctype<char>::id", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::locale::~locale()", referenced from: dlib::fatal_error::check_for_previous_fatal_errors() in libdlib.a(base64_kernel_1.cpp.o) dlib::fatal_error::dlib_fatal_error_terminate() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ios_base::init(void*)", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ios_base::clear(unsigned int)", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ios_base::failure::failure(char const*, std::__1::error_code const&)", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::ios_base::failure::~failure()", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) virtual thunk to std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) virtual thunk to std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_ostringstream() in libdlib.a(base64_kernel_1.cpp.o) "typeinfo for std::__1::basic_ostream<char, std::__1::char_traits<char> >", referenced from: construction vtable for std::__1::basic_ostream<char, std::__1::char_traits<char> >-in-std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) typeinfo for std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "typeinfo for std::__1::basic_streambuf<char, std::__1::char_traits<char> >", referenced from: typeinfo for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "typeinfo for std::__1::ios_base::failure", referenced from: dlib::base64::encode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in libdlib.a(base64_kernel_1.cpp.o) "virtual thunk to std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()", referenced from: construction vtable for std::__1::basic_ostream<char, std::__1::char_traits<char> >-in-std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "virtual thunk to std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()", referenced from: construction vtable for std::__1::basic_ostream<char, std::__1::char_traits<char> >-in-std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libdlib.a(base64_kernel_1.cpp.o) "_dgesdd_", referenced from: int dlib::lapack::gesdd<double, 0l, 2l, 2l, 0l, 0l, 1l, 2l, 0l, dlib::memory_manager_stateless_kernel_1<char> >(char, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 2l, 1l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 2l, 2l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&) in libPoseExprLib.a(DlibWrapper.cpp.o) "_dgesvd_", referenced from: int dlib::lapack::gesvd<double, 0l, 3l, 0l, 3l, 3l, 1l, 3l, 3l, dlib::memory_manager_stateless_kernel_1<char> >(char, char, dlib::matrix<double, 0l, 3l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 3l, 1l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 3l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 3l, 3l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&) in libPoseExprLib.a(DlibWrapper.cpp.o) int dlib::lapack::gesvd<double, 3l, 0l, 3l, 0l, 0l, 1l, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char> >(char, char, dlib::matrix<double, 3l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 1l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 3l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&) in libPoseExprLib.a(DlibWrapper.cpp.o) int dlib::lapack::gesvd<double, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char> >(char, char, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&) in libPoseExprLib.a(DlibWrapper.cpp.o) int dlib::lapack::gesvd<double, 0l, 2l, 2l, 0l, 0l, 1l, 2l, 0l, dlib::memory_manager_stateless_kernel_1<char> >(char, char, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 2l, 1l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 2l, 2l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&, dlib::matrix<double, 0l, 0l, dlib::memory_manager_stateless_kernel_1<char>, dlib::row_major_layout>&) in libPoseExprLib.a(DlibWrapper.cpp.o) ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status

tsconfig.json

答案 10 :(得分:2)

这里没有一个上升的答案对我有用。这是一个有保证的合理解决方案。把它放在使用Promise ...

的任何代码文件的顶部附近
declare const Promise: any;

答案 11 :(得分:1)

我摆脱了index.ts中具有这些组合属性的相同错误:

在tsconfig.json中:

  "compilerOptions": {
    "target": "ES6"

在package.json中:

  "main": "index.ts",
  "scripts": {
    "start": "tsc -p tsconfig.json && node index.js"

答案 12 :(得分:1)

好吧,这可能是违反直觉的,但是我解决了将esnext添加到lib的问题。

{
  "compilerOptions": {
    "lib": [
        "esnext"
    ],
    "target": "es5",
  }
}

编译器建议的FIX是

  

尝试将lib编译器选项更改为es2015或更高版本。

答案 13 :(得分:1)

Core-js对我不起作用,因为它引起了其他问题,但是,只需安装最新版本的npm i @types/es6-promise --save-dev即可解决问题。对我来说问题源于编译使用rxjs的sdk。这是我得到的错误:

`node_modules/rxjs/Observable.d.ts(59,60): error TS2693: Promise only refers to a type, but is being used as a value here.`

答案 14 :(得分:1)

如果您在项目中使用DefinitelyTyped存储库,则可能遇到this recent issue

您可能使用的一个不错的解决方法(除了等待定义文件的更新版本或重构您的TS代码之外)是为core-js类型指定显式版本+构建,而不是让Visual Studio选择最新的/最近的一个。我发现一个似乎不受此问题的影响(至少在我的情况下),您可以使用它替换 package.jso n文件中的以下行:

  "scripts": {
    "postinstall": "typings install dt~core-js --global"
  }

使用以下内容:

  "scripts": {
    "postinstall": "typings install dt~core-js@0.9.7+20161130133742 --global"
  }

这解决了我的问题。但是,强烈建议在问题发布后立即删除显式版本+构建引用。

有关此问题的更多信息,您还可以read this blog post我就该主题撰写的内容。

答案 15 :(得分:0)

我正在使用"promise-polyfill"库,这可能是我问题的原因。

我将此导入添加到文件顶部:

import {Promise} from 'es6-promise';

答案 16 :(得分:0)

npm i --save-dev @ types / es6-promise

启动命令后,您最好检查tsconfig.json,确保&#34; target&#34;必须伟大而不是&#34; es6&#34;。也许tsc还不支持es5。

答案 17 :(得分:0)

花了很多时间试图解决这个问题。我在这里或其他地方提供的任何解决方案都没有运气。

但后来发现它并不仅仅是解决问题。但是你还需要重新启动VSCODE才能生效。

答案 18 :(得分:0)

只需将目标更改为&#34; ES2017&#34;在tsconfig.json文件中。

这是我的tsconfig.json文件

{
"compilerOptions": {
/* Basic Options */
    "target": "ES2017",   /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
    "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "declaration": true,  /* Generates corresponding '.d.ts' file. */
    "sourceMap": true,    /* Generates corresponding '.map' file. */
    "outDir": "./dist",   /* Redirect output structure to the directory. */
    "strict": true        /* Enable all strict type-checking options. */
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

答案 19 :(得分:0)

我遇到了同样的问题,这使我免于第二个问题:

在控制台中写这个:

urllib.request.urlopen(url)

在问题所在的文件中复制粘贴:

npm i --save bluebird
npm i --save-dev @types/bluebird @types/core-js@0.9.36

答案 20 :(得分:0)

我遇到了相同的错误,并使用以下配置对其进行了修复:

文件:tsconfig.json

  constructor(private route: ActivatedRoute) { }
  this.route.params.subscribe(params => {
    this.userdetails=params.token;
  });
}

答案 21 :(得分:0)

请注意,如果您运行的tsc命令的文件名为:

tsc testfile.ts

然后将忽略tsconfig.json编译器配置文件。 解决方案是单独运行tsc命令,否则将编译目录中的所有.ts文件,除非您已编辑tsconfig.json以包含一组文件。

请参阅“使用文件属性” ... https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

答案 22 :(得分:0)

这里有同样的错误。我在tsconfig中使用“模块”:“ ES6”修复了该问题。