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

Different weird issues when something imported from 'typescript' module #266

Open
anpur opened this issue Apr 26, 2018 · 2 comments
Open

Comments

@anpur
Copy link

anpur commented Apr 26, 2018

Issue

Weird resolving issues happen as soon as import form typescript module added:

import { transform } from 'typescript';

Error example 1

Buffer module was resolved as empty.js (as I've found from bundled file in temp dir) despite having addNodeGlobals and even buffer module installed manually.

Uncaught TypeError: Cannot read property 'isBuffer' of undefined\nat /var/folders/01/xnjcgz3d5x16_nzyt82rjh1c07pp5j/T/karma-typescript-bundle-4483FfKhLR6XL56f.js:19867:27

One of my files was referencing uuid js module, which is using buffer module imported. Works if typescript import removed.

In bundle file:

global.process=require('_process');
global.Buffer=require('buffer').Buffer;
},'bundle/node-globals',{"_process":"/Users/apurin/Repos/twilsock.js/node_modules/process/browser.js","buffer":"/Users/apurin/Repos/twilsock.js/node_modules/browser-resolve/empty.js"}];

How to repro

tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "sourceMap": true,
        "declaration": true,
        "noImplicitAny": false,
        "preserveConstEnums": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es2017",
        "lib": [ "es7", "dom" ]
    },
    "include": [
        "issue.ts"
    ]
}

karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['karma-typescript'],
    files: [ 'issue.ts' ],
    preprocessors: { 'issue.ts': ['karma-typescript'] },
    reporters: ['karma-typescript'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['Chrome'],
    singleRun: true,
    concurrency: Infinity,
    karmaTypescriptConfig: {
      compilerOptions: {
        target: 'es5',
        sourceMap: true
      },
      bundlerOptions: {
        addNodeGlobals: true,
        sourceMap: true
      },
      tsconfig: './tsconfig.json'
    }
  });
};

issue.ts:

import { transform } from 'typescript';
@anpur
Copy link
Author

anpur commented Apr 26, 2018

Forgot to add exact version (but issue persisted through all karma/npm versions I've tried). Those are latest version on this moment:

  "devDependencies": {
    "karma": "^2.0.2",
    "karma-chrome-launcher": "^2.2.0",
    "karma-typescript": "^3.0.12",
    "typescript": "^2.8.3"
  }

@erikbarke
Copy link
Collaborator

This isn't supported yet, I'll leave this open!

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

No branches or pull requests

2 participants