Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In "nodejs" version v13.2.0, using "ts-node" ,".ts" files cannot be compiled into "ES2015" modules and work #923

Closed
masx200 opened this issue Dec 12, 2019 · 1 comment

Comments

@masx200
Copy link

masx200 commented Dec 12, 2019

In "nodejs" version v13.2.0, ".ts" files cannot be compiled into "ES2015" modules using "ts-node"

Running "ts-node ./rename-by-md5.ts" will report an error.

but Run "tsc && node ./rename-by-md5.js", the program will work normally

 ts-node ./rename-by-md5.ts
(node:1784) ExperimentalWarning: The ESM module loader is experimental.
SyntaxError: Unexpected token ':'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:84:18)
    at link (internal/modules/esm/module_job.js:36:21)
error Command failed with exit code 1.

tsconfig.json

{
    "compilerOptions": {
        "declaration": true,
        "noUnusedLocals": true,
        "checkJs": true,
        "importHelpers": true,
        "removeComments": true,
        "allowJs": true,
        "target": "esnext",
        "module": "es2015",
        "strict": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true
    }
}

package.json

{
  "type": "module",
  "types": "rename-by-md5.ts",
  "name": "@masx200/rename-by-md5",
  "version": "1.0.0",
  "main": "rename-by-md5.js",
  "license": "MIT",
  "scripts": {
    "start": "tsc && node ./rename-by-md5.js"
  },
  "dependencies": {
    "@types/find": "^0.2.1",
    "@types/md5-file": "^4.0.0",
    "@types/node": "^12.12.17",
    "find": "^0.3.0",
    "md5-file": "^4.0.0",
    "ts-node": "^8.5.4",
    "tslib": "^1.10.0",
    "typescript": "^3.7.3"
  },
  "devDependencies": {},
  "keywords": [],
  "author": "masx200 <34191203+masx200@users.noreply.github.com>",
  "description": "批量使用文件的md5值给文件重命名",
  "repository": "git+https://github.com/masx200/rename-by-md5.git",
  "bugs": {
    "url": "https://github.com/masx200/rename-by-md5/issues"
  },
  "homepage": "https://github.com/masx200/rename-by-md5#readme"
}

rename-by-md5.ts

import find from "find";
import fs from "fs";
import md5file from "md5-file";
import path from "path";
function md5FileAsPromised(filename: string): Promise<string> {
  return new Promise(function(resolve, reject) {
    md5file(filename, function(err, hash) {
      if (err) {
        return reject(err);
      } else {
        resolve(hash);
      }
    });
  });
}
@masx200 masx200 changed the title 在“ nodejs”版本v13.2.0中无法正常编译成“ ES2015”模块使用“ ts-node” In "nodejs" version v13.2.0 cannot be compiled into "ES2015" module normally using "ts-node" Dec 12, 2019
@masx200 masx200 changed the title In "nodejs" version v13.2.0 cannot be compiled into "ES2015" module normally using "ts-node" In "nodejs" version v13.2.0, ".ts" files cannot be compiled into "ES2015" modules using "ts-node" Dec 12, 2019
@masx200 masx200 changed the title In "nodejs" version v13.2.0, ".ts" files cannot be compiled into "ES2015" modules using "ts-node" In "nodejs" version v13.2.0, using "ts-node" ,".ts" files cannot be compiled into "ES2015" modules and work Dec 12, 2019
@blakeembrey
Copy link
Member

This is unfortunately expected behavior, see #436 if you’d like to help support it. I haven’t had the capacity to dive into the latest module loader configuration yet, or figure out the trickier cases of actually allowing an import of a file that doesn’t exist yet because you need to specify extensions now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants