【问题标题】:Is it possible to use EaselJS (CreateJS) with TypeScript using parceljs?是否可以使用 parceljs 将 EaselJS (CreateJS) 与 TypeScript 一起使用?
【发布时间】:2020-11-06 17:13:47
【问题描述】:

我正在尝试使用 EaselJS 制作游戏,并且由于是 [当年],因此我正在使用 TypeScript。我在here 中使用了 “官方” 类型,但我无法将它与 parceljs 一起使用。如果我导入类型,包裹会失败。如果我在没有类型的情况下导入,parcel 很高兴(并且我的构建工作),但我在 VS Code 中没有类型。

这是我的导入,适用于包裹构建:

import * as createjs from '@createjs/easeljs';

VS Code 在此行抛出一个信息警告,指出 Could not find a declaration file for module '@createjs/easeljs'.,并且类型不起作用。

这是一个让 VS Code 开心,但又让人难过的导入:

import 'createjs';

现在 EaselJS 的类型可以在 VS Code 中使用,但是包裹构建失败并显示 src/main.ts:3:8: Cannot resolve dependency 'createjs'。不酷!

这是我的 package.json:

{
  "name": "corona-coaster",
  "version": "0.1.0",
  "license": "GPL-3.0-only",
  "dependencies": {
    "@createjs/easeljs": "^2.0.0-beta.4",
    "createjs": "^1.0.1",
    "sty": "^0.6.1"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.11.0",
    "@types/createjs": "^0.0.29",
    "@types/easeljs": "^1.0.0",
    "@types/jest": "^26.0.4",
    "@types/tweenjs": "^1.0.1",
    "jest": "^26.1.0",
    "jest-extended": "^0.11.5",
    "parcel-bundler": "^1.12.4",
    "sass": "^1.26.10",
    "ts-jest": "^26.1.1",
    "typescript": "^3.9.6"
  },
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build index.html --public-url ./",
    "test": "jest"
  },
  "jest": {
    "preset": "ts-jest",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/testSetup.ts"
    ]
  }
}

还有我的 tsconfig:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "~/*": [
        "./*"
      ]
    },
    "typeRoots": [
      "node_modules/@types"
    ]
  }
}

GitHub 存储库是 here。我无法切换到 webpack。

【问题讨论】:

    标签: typescript visual-studio-code createjs easeljs parceljs


    【解决方案1】:

    我找到了解决方法。请改用 createjs-module 包,并将其用作您的导入语句:

    import * as createjs from 'createjs-module';
    

    恭喜!斗争现在结束了。不需要在tsconfig 中做任何特别的事情,也不需要自己包含类型——它们包含在createjs-module 中。整洁!

    归功于this comment

    【讨论】:

      猜你喜欢
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 2021-11-12
      • 2016-04-01
      • 2011-01-20
      • 2018-08-11
      • 2021-08-05
      相关资源
      最近更新 更多