微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法将System.js添加到我的打字稿项目中

如何解决无法将System.js添加到我的打字稿项目中

我有一个现有的打字稿项目,现在我想在其中使用一些库。它已配置为生成outputFile,因此我需要设置模块:“ System”,这已经完成了两次。此外,我还在index.html上添加了systemJS。但是有一个很大的问题-每当我尝试导入js文件时,使用systemjs效果都很好-我可以使用在其中声明的所有函数,依此类推。但是,当我在文件中包含任何导入(例如,从“ someconst”导入{A})时,systemjs就会停止处理大量错误消息

Uncaught ReferenceError: System is not defined
Uncaught (in promise) TypeError: hello.init is not a function
Uncaught TypeError: Cannot read property 'apply' of null
    at window.onerror (common.js:143)

这是我在index.html中添加systemjs的方式:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.20.1/system.js" integrity="sha512-7srDmqummlvkixi8/FhTwAQCedVevJFHf9toA+c7CuCuP3dQxVhP7hPm05hkbGDHyDbwWdLCEg/AhO21Wb375Q==" crossorigin="anonymous">
</script>

<script>
    System.import('js/map.js').then(function (hello) {
        hello.init();
        console.log(hello)
    });

</script>

这是我的map.ts,然后将其编译成js / map.js 从“ sometext”导入{A}

function init() {
   console.log(A);
}

我用来测试导入的sometext.js:

export const A = "AAABBBCCC"

还有我的tsconfig

{
  "compileOnSave": true,"compilerOptions": {
    "noImplicitAny": false,"noEmitOnError": true,"removeComments": false,"sourceMap": true,"module": "System","target": "es5","outFile": "../../wwwroot/js/map.js"
  },"exclude": [
  ]
}

我在做什么错?似乎systemjs可以完美运行,但是当我导入任何东西时,它就会崩溃。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。