hq: Error resolving module specifier in raw tsc --init project

Uncaught TypeError: Error resolving module specifier “\render”. Relative module specifiers must start with “./”, “../” or “/”.

typescript 4.0.3 node 12.18.4 or 14.12.0

The most basic of basic typescript projects seem to be broken now. This wasn’t broken the last time I was playing with this project. image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Remote debugging is painful. Hope 0.0.26 will work. I honestly do not understand why it’s not working without index.html, but let’s try and see.

Thanks so much for resolving this for me right before your vacation! 😄

http://localhost:8080/ Fail http://localhost:8080/index.html “Succeed”

Logs in Firefox:

Loading module from “http://localhost:8080/hq-livereload.js” was blocked because of a disallowed MIME type (“text/plain”).
index.html
Loading failed for the module with source “http://localhost:8080/hq-livereload.js”. index.html:14:1
Loading module from “http://localhost:8080/index.ts” was blocked because of a disallowed MIME type (“text/plain”).
index.html
Loading failed for the module with source “http://localhost:8080/index.ts”. index.html:11:1
L:\git\zageron\scratch>hq --verbose
(c) hqjs @ 0.0.25
Start time: 0.2 s

Visit http://localhost:8080
or http://192.168.1.239:8080 within local network


| hq root    : C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq

| root       : L:\git\zageron\scratch
| src        : src

| certs      :

| babelrc    : undefined
| postcssrc  : undefined
| posthtmlrc : undefined


�  USER AGENT Firefox 81.0 for desktop

✔️   SUPPORT    true

❌ Error /: File / not found

NotFoundError: File / not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:37:5
    at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5

�  RESOLVE    /index.html: L:\git\zageron\scratch\src\index.html 358b

ℹ️   STATS      /index.html: text/html source

�   ETAG       /index.html: version 0 - 200 OK

�️   BUILD      /index.html: Firefox 81.0 for desktop

�  SEND       /index.html

�  RESOLVE    /hq-livereload.js: C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\hq-livereload.js\ 207b

ℹ️   STATS      /hq-livereload.js: application/javascript source
�   ETAG       /hq-livereload.js: version 0 - 200 OK
�️   BUILD      /hq-livereload.js: Firefox 81.0 for desktop

�  RESOLVE    /index.ts: L:\git\zageron\scratch\src\index.ts 120b

ℹ️   STATS      /index.ts: application/javascript source
�   ETAG       /index.ts: version 0 - 200 OK
�️   BUILD      /index.ts: Firefox 81.0 for desktop

❌ Error /hq-livereload.js: File URL path must be absolute

TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at getPathFromURLWin32 (internal/url.js:1321:11)
    at Object.fileURLToPath (internal/url.js:1351:22)
    at urlToPath (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/utils.mjs:67:11)
    at compileJS (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/compilers/js.mjs:567:72)
    at async buildSource (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:21:13)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:107:5
    at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5


  TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
      at getPathFromURLWin32 (internal/url.js:1321:11)
      at Object.fileURLToPath (internal/url.js:1351:22)
      at urlToPath (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/utils.mjs:67:11)
      at compileJS (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/compilers/js.mjs:567:72)
      at async buildSource (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:21:13)
      at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:107:5
      at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
      at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5


❌ Error /index.ts: File URL path must be absolute

TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at getPathFromURLWin32 (internal/url.js:1321:11)
    at Object.fileURLToPath (internal/url.js:1351:22)
    at urlToPath (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/utils.mjs:67:11)
    at compileJS (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/compilers/js.mjs:567:72)
    at async buildSource (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:21:13)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:107:5
    at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5


  TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
      at getPathFromURLWin32 (internal/url.js:1321:11)
      at Object.fileURLToPath (internal/url.js:1351:22)
      at urlToPath (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/utils.mjs:67:11)
      at compileJS (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/compilers/js.mjs:567:72)
      at async buildSource (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:21:13)
      at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/build.mjs:107:5
      at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
      at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5

Bingo! It looks like what we need. I’ll add exception for windows and release in couple of minutes.

L:\git\zageron\scratch>node
Welcome to Node.js v14.10.0.
Type ".help" for more information.
> url = require('url');
(path.resolve('L:\git\zageron\scratch', path.join('src', urlToPath('/index.html'))));{
  Url: [Function: Url],
  parse: [Function: urlParse],
  resolve: [Function: urlResolve],
  resolveObject: [Function: urlResolveObject],
  format: [Function: urlFormat],
  URL: [class URL],
  URLSearchParams: [class URLSearchParams],
  domainToASCII: [Function: domainToASCII],
  domainToUnicode: [Function: domainToUnicode],
  pathToFileURL: [Function: pathToFileURL],
  fileURLToPath: [Function: fileURLToPath]
}
> path = require('path');
<ref *1> {
  resolve: [Function: resolve],
  normalize: [Function: normalize],
  isAbsolute: [Function: isAbsolute],
  join: [Function: join],
  relative: [Function: relative],
  toNamespacedPath: [Function: toNamespacedPath],
  dirname: [Function: dirname],
  basename: [Function: basename],
  extname: [Function: extname],
  format: [Function: bound _format],
  parse: [Function: parse],
  sep: '\\',
  delimiter: ';',
  win32: [Circular *1],
  posix: <ref *2> {
    resolve: [Function: resolve],
    normalize: [Function: normalize],
    isAbsolute: [Function: isAbsolute],
    join: [Function: join],
    relative: [Function: relative],
    toNamespacedPath: [Function: toNamespacedPath],
    dirname: [Function: dirname],
    basename: [Function: basename],
    extname: [Function: extname],
    format: [Function: bound _format],
    parse: [Function: parse],
    sep: '/',
    delimiter: ':',
    win32: [Circular *1],
    posix: [Circular *2],
    _makeLong: [Function: toNamespacedPath]
  },
  _makeLong: [Function: toNamespacedPath]
}
> urlToPath = urlPath => url.fileURLToPath(urlPath.startsWith('file:/') ? urlPath : `file:/${urlPath}`);
[Function: urlToPath]
> console.log(urlToPath('/index.html'));
\\index.html\
undefined
> console.log(path.join('src', urlToPath('/index.html')));
src\index.html\
undefined
> console.log(path.resolve('L:\git\zageron\scratch', path.join('src', urlToPath('/index.html'))));
L:\git\zageron\scratch\gitzageronscratch\src\index.html
undefined
L:\git\zageron\scratch>node
Welcome to Node.js v14.10.0.
Type ".help" for more information.
> url = require('url');
{
  Url: [Function: Url],
  parse: [Function: urlParse],
  resolve: [Function: urlResolve],
  resolveObject: [Function: urlResolveObject],
  format: [Function: urlFormat],
  URL: [class URL],
  URLSearchParams: [class URLSearchParams],
  domainToASCII: [Function: domainToASCII],
  domainToUnicode: [Function: domainToUnicode],
  pathToFileURL: [Function: pathToFileURL],
  fileURLToPath: [Function: fileURLToPath]
}
> path = require('path');
<ref *1> {
  resolve: [Function: resolve],
  normalize: [Function: normalize],
  isAbsolute: [Function: isAbsolute],
  join: [Function: join],
  relative: [Function: relative],
  toNamespacedPath: [Function: toNamespacedPath],
  dirname: [Function: dirname],
  basename: [Function: basename],
  extname: [Function: extname],
  format: [Function: bound _format],
  parse: [Function: parse],
  sep: '\\',
  delimiter: ';',
  win32: [Circular *1],
  posix: <ref *2> {
    resolve: [Function: resolve],
    normalize: [Function: normalize],
    isAbsolute: [Function: isAbsolute],
    join: [Function: join],
    relative: [Function: relative],
    toNamespacedPath: [Function: toNamespacedPath],
    dirname: [Function: dirname],
    basename: [Function: basename],
    extname: [Function: extname],
    format: [Function: bound _format],
    parse: [Function: parse],
    sep: '/',
    delimiter: ':',
    win32: [Circular *1],
    posix: [Circular *2],
    _makeLong: [Function: toNamespacedPath]
  },
  _makeLong: [Function: toNamespacedPath]
}
> urlToPath = urlPath => url.fileURLToPath(urlPath.startsWith('file://') ? urlPath : `file://${urlPath}`);
[Function: urlToPath]
> console.log(urlToPath('/index.html'));
Uncaught TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at getPathFromURLWin32 (internal/url.js:1321:11)
    at Object.fileURLToPath (internal/url.js:1351:22)
    at urlToPath (REPL3:1:28)
    at REPL4:1:13
    at Script.runInThisContext (vm.js:132:18)
    at REPLServer.defaultEval (repl.js:479:29)
    at bound (domain.js:430:14)
    at REPLServer.runBound [as eval] (domain.js:443:12)
    at REPLServer.onLine (repl.js:809:10)
    at REPLServer.emit (events.js:326:22) {
  code: 'ERR_INVALID_FILE_URL_PATH'
}
> console.log(path.join('src', urlToPath('/index.html')));
Uncaught TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at getPathFromURLWin32 (internal/url.js:1321:11)
    at Object.fileURLToPath (internal/url.js:1351:22)
    at urlToPath (REPL3:1:28)
    at REPL5:1:30
    at Script.runInThisContext (vm.js:132:18)
    at REPLServer.defaultEval (repl.js:479:29)
    at bound (domain.js:430:14)
    at REPLServer.runBound [as eval] (domain.js:443:12)
    at REPLServer.onLine (repl.js:809:10)
    at REPLServer.emit (events.js:326:22) {
  code: 'ERR_INVALID_FILE_URL_PATH'
}
> console.log(path.resolve('L:\git\zageron\scratch', path.join('src', urlToPath('/index.html'))));
Uncaught TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at getPathFromURLWin32 (internal/url.js:1321:11)
    at Object.fileURLToPath (internal/url.js:1351:22)
    at urlToPath (REPL3:1:28)
    at REPL6:1:69
    at Script.runInThisContext (vm.js:132:18)
    at REPLServer.defaultEval (repl.js:479:29)
    at bound (domain.js:430:14)
    at REPLServer.runBound [as eval] (domain.js:443:12)
    at REPLServer.onLine (repl.js:809:10)
    at REPLServer.emit (events.js:326:22) {
  code: 'ERR_INVALID_FILE_URL_PATH'
}

@Zageron Can you please run node in the project root

node

And then execute few lines of code to test how it works on Windows system?

url = require('url');
path = require('path');
urlToPath = urlPath => url.fileURLToPath(urlPath.startsWith('file://') ? urlPath : `file://${urlPath}`);
console.log(urlToPath('/index.html'));
console.log(path.join('src', urlToPath('/index.html')));
console.log(path.resolve('L:\git\zageron\scratch', path.join('src', urlToPath('/index.html'))));

Hey, can you please test new version 0.0.24 so I will be able to release supplementary VSCode plugin?

Thanks a lot for the detailed logs. Usually just a problem statement is enough, but I have no windows machine so it is much easier with the log in this case. I’m going for vacation tomorrow, will try to find the issue before that. Sorry for inconvenience.

@Zageron can you please give me the output of hq --verbose and separate results of requesting /render.ts and /index.ts?