Skip to content
New issue

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

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

Already on GitHub? # to your account

ncc@0.11.0 typescript error #237

Closed
transitive-bullshit opened this issue Jan 23, 2019 · 5 comments · Fixed by #244
Closed

ncc@0.11.0 typescript error #237

transitive-bullshit opened this issue Jan 23, 2019 · 5 comments · Fixed by #244

Comments

@transitive-bullshit
Copy link

The included typescript example throws a build error for me using 0.11.0 but compiles fine with 0.9.0.

> yarn
> yarn build
Error: Hash: 68dec8e1900ae0e3b2dd
Version: webpack 5.0.0-alpha.0
Time: 127ms
Built at: 01/22/2019 7:07:23 PM
   Asset      Size  Chunks  Chunk Names
index.js  2.32 KiB   {404}  main
Entrypoint main = index.js
[548] ./index.ts 1.11 KiB {404} [built] [failed] [1 error]

ERROR in ./index.ts
Module build failed (from (webpack)/ncc/loaders/ts-loader.js):
Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/loaders/ts-loader.js:1:194100)
    at __webpack_require__ (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/loaders/ts-loader.js:1:216)
    at Object.<anonymous> (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/loaders/ts-loader.js:1:113665)
    at __webpack_require__ (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/loaders/ts-loader.js:1:216)
    at Object.<anonymous> (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/loaders/ts-loader.js:1:210066)
    at __webpack_require__ (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/loaders/ts-loader.js:1:216)

    at compiler.close.n (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/index.js:1:399469)
    at _promise0.then._result0 (eval at create (/Users/tfischer/dev/temp/ncc-test/node_modules/@zeit/ncc/dist/ncc/index.js:1:1105949), <anonymous>:13:1)
error Command failed with exit code 1.

If I change package.json to have "@zeit/ncc": "0.9.0", the build works as intended.

I was getting this error in a more complicated scenario, so I tried the built-in typescript example and got the same results.

I'm guessing this was introduced in 208cdc0.

I do have typescript installed globally. tsc --version yields 3.2.4.

node: v10.3.0
yarn: 1.13.0
macOS High Sierra 10.13.6

cc @guybedford @rauchg

@samkcarlile
Copy link

I'm having this exact issue. Same versions on everything except I'm using NPM, so it's definitely not specific to Yarn

@samkcarlile
Copy link

Try installing typescript locally, that may have been my issue (I thought I had it installed local previously). @transitive-bullshit

@transitive-bullshit
Copy link
Author

Indeed, running yarn add --dev typescript locally resolved the issue, but the bug should still be fixed.

Thanks @samkcarlile!

@Foxhunt
Copy link

Foxhunt commented Jan 27, 2019

I have the same issue.

node: v10.15.0
ncc: 0.11.0
tsc: 3.2.4

ncc is installed globally.

Installing typescript globally solves it for me. Installing it locally gives me the error.

Installing both locally and running ncc via npx works as well.

Seems like they must both be installed at the same location.

@mikaelbr
Copy link

mikaelbr commented Jan 28, 2019

Looks like the issue might stems from here https://github.com/zeit/ncc/blob/master/src/loaders/ts-loader.js#L21 which after #233 is no longer working. Looks like require.resolve might cause some issues here if you want to use local ./typescript.js. Not on my pc right now so can't test/verify myself. But maybe something like changing from

const tsId = require.resolve("typescript");

to

const tsId = getTsId();

// ...
function getTsId() {
  try {
    return require.resolve('typescript');
  }
  catch (e) {
    return require.resolve(__dirname + "/../../dist/ncc/typescript/typescript.js");
  }
}

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

Successfully merging a pull request may close this issue.

4 participants