GlassBricks / typed-factorio

Complete and featureful Typescript defintions for the Factorio modding API
MIT License
33 stars 3 forks source link

node_modules/typed-factorio/generated/classes.d.ts(261,3): error TS2304: Cannot find name 'https'. #13

Closed aSemy closed 2 years ago

aSemy commented 2 years ago

Hi, I'm getting a new error after updating to v1.1.0.

If I downgrade to v1.0.0 it works correctly, no errors.

TSTL seems to run okay, but something fails on the last step.

Including lualib bundle
Emitting output
Emitting ...
Emitting ...
Emitting ...
Emitting ...
Emit finished!
node_modules/typed-factorio/generated/classes.d.ts(238,3): error TS2304: Cannot find name 'https'.
node_modules/typed-factorio/generated/classes.d.ts(261,3): error TS2304: Cannot find name 'https'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-factorio-mod@0.5.0 build: `tstl "--outDir" "my-project\build\tmp\typescriptToLua"`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the kafkatorio-events-mod@0.5.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ...\npm-cache\_logs\2022-05-14T11_30_03_008Z-debug.log
...
package.json
{
  "name": "my-factorio-mod",
  "version": "0.5.0",
  "private": true,
  "scripts": {
    "build": "tstl",
    "dev": "tstl --watch"
  },
  "engines": {
    "node": "~14.19.1"
  },
  "devDependencies": {},
  "dependencies": {
    "lua-types": "^2.11.0",
    "typescript-to-lua": "1.4.4",
    "typed-factorio": "1.1.0",
    "typescript": "4.6.4"
  },
  "license": "UNLICENSED",
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
tsconfig.json
{
  "$schema": "https://raw.githubusercontent.com/TypeScriptToLua/vscode-typescript-to-lua/master/tsconfig-schema.json",
  "compilerOptions": {
    "target": "esnext",
    "lib": [
      "esnext"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "types": [
      "typescript-to-lua/language-extensions",
      "lua-types/5.2",
      "typed-factorio/runtime"
    ],
    "plugins": [
      {
        "name": "typescript-tstl-plugin"
      }
    ],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "explainFiles": true,
    "forceConsistentCasingInFileNames": true,
    "listEmittedFiles": true,
    "listFiles": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "sourceMap": false,
    "strict": true,
    "strictFunctionTypes": true,
    "strictNullChecks": true,
    "traceResolution": true,
    "noImplicitReturns": true,
    "noImplicitOverride": true,
    "noFallthroughCasesInSwitch": true
  },
  "tstl": {
    "luaTarget": "5.2",
    "tstlVerbose": true,
    "noHeader": true,
    "noImplicitSelf": true,
    "luaLibImport": "require"
  }
}
npm-cache log
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '..\\my-project\\.gradle\\nodejs\\node-v14.19.1-win-x64\\node.exe',
1 verbose cli   '..\\my-project\\.gradle\\nodejs\\node-v14.19.1-win-x64\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build',
1 verbose cli   '--',
1 verbose cli   '--outDir',
1 verbose cli   '..\\my-project\\build\\tmp\\typescriptToLua'
1 verbose cli ]
2 info using npm@6.14.16
3 info using node@v14.19.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle my-factorio-mod@0.5.0~prebuild: my-factorio-mod@0.5.0
6 info lifecycle my-factorio-mod@0.5.0~build: my-factorio-mod@0.5.0
7 verbose lifecycle my-factorio-mod@0.5.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle my-factorio-mod@0.5.0~build: PATH: ..\my-project\.gradle\nodejs\node-v14.19.1-win-x64\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;..\my-project\src\main\typescript\node_modules\.bin;..\my-project\.gradle\nodejs\node-v14.19.1-win-x64;..\my-project\.gradle\nodejs\node-v14.19.1-win-x64;C:\ProgramData\scoop\apps\temurin-lts-jdk\current\bin;C:\ProgramData\scoop\shims;...
9 verbose lifecycle my-factorio-mod@0.5.0~build: CWD: ..\my-project\src\main\typescript
10 silly lifecycle my-factorio-mod@0.5.0~build: Args: [
10 silly lifecycle   '/d /s /c',
10 silly lifecycle   'tstl "--outDir" "..\\my-project\\build\\tmp\\typescriptToLua"'
10 silly lifecycle ]
11 silly lifecycle my-factorio-mod@0.5.0~build: Returned: code: 2  signal: null
12 info lifecycle my-factorio-mod@0.5.0~build: Failed to exec build script
13 verbose stack Error: my-factorio-mod@0.5.0 build: `tstl "--outDir" "..\my-project\build\tmp\typescriptToLua"`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (..\my-project\.gradle\nodejs\node-v14.19.1-win-x64\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:400:28)
13 verbose stack     at ChildProcess.<anonymous> (..\my-project\.gradle\nodejs\node-v14.19.1-win-x64\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:400:28)
13 verbose stack     at maybeClose (internal/child_process.js:1058:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)
14 verbose pkgid my-factorio-mod@0.5.0
15 verbose cwd ..\my-project\src\main\typescript
16 verbose Windows_NT 10.0.19044
17 verbose argv "..\\my-project\\.gradle\\nodejs\\node-v14.19.1-win-x64\\node.exe" "..\\my-project\\.gradle\\nodejs\\node-v14.19.1-win-x64\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" "--" "--outDir" "..\\my-project\\build\\tmp\\typescriptToLua"
18 verbose node v14.19.1
19 verbose npm  v6.14.16
20 error code ELIFECYCLE
21 error errno 2
22 error my-factorio-mod@0.5.0 build: `tstl "--outDir" "..\my-project\build\tmp\typescriptToLua"`
22 error Exit status 2
23 error Failed at the my-factorio-mod@0.5.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
aSemy commented 2 years ago

If I manually edit classes.d.ts and comment out the JSDoc above on_init(), then doesn't complain! Very weird!


  // /**
  //  * Register a function to be run on mod initialization. This is only called when a new save game is created or when a save file is loaded that previously didn't contain the mod. During it, the mod gets the chance to set up initial values that it will use for its lifetime. It has full access to {@link LuaGameScript} and the {@link https://lua-api.factorio.com/latest/Global.html global} table and can change anything about them that it deems appropriate. No other events will be raised for the mod until it has finished this step.
  //  *
  //  * {@link https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_init View documentation}
  //  *
  //  * ASd
  //  *
  //  * @param f The handler for this event. Passing `nil` will unregister it.
  //  * @remarks For more context, refer to the {@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle} page.
  //  * @example Initialize a `players` table in `global` for later use.
  //  *
  //  * ```
  //  * script.on_init(function()
  //  *   global.players = {}
  //  * end)
  //  * ```
  //  */
  on_init(f: (() => void) | undefined): void

No more error for on_init():

...
Emit finished!
node_modules/typed-factorio/generated/classes.d.ts:267:3 - error TS2304: Cannot find name 'https'.

267   on_configuration_changed(f: ((param1: ConfigurationChangedData) => void) | undefined): void
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Process finished with exit code 2
aSemy commented 2 years ago

It's something to do with the {@link https...} inside the @remarks block.

I can't find anyone else who's had this issue.

If I wrap the link in backticks then compilation works, and the link seems to render correctly UPDATE but it's not valid, and I can't click on it.

  * @remarks For more context, refer to the {@link `https://lua-api.factorio.com/latest/Data-Lifecycle.html` Data Lifecycle} page.
aSemy commented 2 years ago

It looks like this might be a TSTL issue https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1058

GlassBricks commented 2 years ago

This seems to be a Typescript issue. I couldn't find a nice workaround for this in typed-factorio; we'll have to wait for Typescript's response.

For now, a workaround is to add skipLibCheck: true to your tsconfig > compilerOptions.

aSemy commented 2 years ago

Great, that works, thanks! That's much better than the hack I implemented.

aSemy commented 2 years ago

I was doing some investigation in https://github.com/microsoft/TypeScript/issues/49109 and I think I found a workaround: change {@link ...} to {@linkplain ...} when it refers to https links.

GlassBricks commented 2 years ago

Thanks for the tip! v1.3.1 now uses @linkplain instead of @link for web links. Hopefully this works around this issue.

aSemy commented 2 years ago

Sorry, false alarm - I get exactly the same error with @linkplain :(

https://typescripttolua.github.io/play/#code/JYOwLgpgTgZghgYwgAgDIFc4CED2OwDOYUcADsgN4BQyyA9AFQM20PIACUEAtnFANYEWyZrRGV2AG1D9SkuKGQALMGFIEAXHToBzYGCXoARgDoEObgF9hDOixwgA+qH0AKGBuREooHQEpPADccYAATKmsqcxAiLwQfUjBkTwxsPEJiMmQAXkphZAdnEH1PVwAPPxyAPkpka0iCeOBEk0KXMFcAIhg8Tr8qIA

GlassBricks commented 2 years ago

Oh well; no harm done; web links usually want to be plain links anyways.

For now, in v1.3.2, I've moved the notes comment into the main body of the doc comment, avoiding @remarks entirely.

Closing this issue for now. If Typescript fixes their bug in the future, we may move back to using @remarks.