Help needed: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node

Today I noticed that I can no longer build my app locally using ember build -prod. CI builds fine and ember server works without issues as well. This is the error I am seeing:

Build Error (Filter) in assets/auto-import-fastboot-4c714e85e4221f8fc7a6c5c479aab887.js

The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node


Stack Trace and Error Report: /var/folders/yt/kw3pd9l52sd9bbpjrlpm47rm0000gn/T/error.dump.0037d8464d97591f58ec1a4589a7e0b7.log

This is the error description from error.dump.0037d8464d97591f58ec1a4589a7e0b7.log

ERROR Summary:

  - broccoliBuilderErrorStack: TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node
    at Object.writeFileSync (fs.js:1409:5)
    at asyncOutputFilteredFile (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/index.js:173:12)
    at tryCatch (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:538:13)
    at /Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:606:14
    at flush (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:2415:5)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

  - code: [undefined]
  - codeFrame: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node
  - errorMessage: assets/auto-import-fastboot-4c714e85e4221f8fc7a6c5c479aab887.js: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node
        in /var/folders/yt/kw3pd9l52sd9bbpjrlpm47rm0000gn/T/broccoli-39164X71aTw4kXt5G/out-666-broccoli_persistent_filter_fastboot_manifest_rewrite_brocco
        at Filter
  - errorType: Build Error
  - location:
    - column: [undefined]
    - file: assets/auto-import-fastboot-4c714e85e4221f8fc7a6c5c479aab887.js
    - line: [undefined]
    - treeDir: /var/folders/yt/kw3pd9l52sd9bbpjrlpm47rm0000gn/T/broccoli-39164X71aTw4kXt5G/out-666-broccoli_persistent_filter_fastboot_manifest_rewrite_brocco
  - message: assets/auto-import-fastboot-4c714e85e4221f8fc7a6c5c479aab887.js: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node
        in /var/folders/yt/kw3pd9l52sd9bbpjrlpm47rm0000gn/T/broccoli-39164X71aTw4kXt5G/out-666-broccoli_persistent_filter_fastboot_manifest_rewrite_brocco
        at Filter
  - name: Error
  - nodeAnnotation: [undefined]
  - nodeName: Filter
  - originalErrorMessage: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node
  - stack: TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Node
    at Object.writeFileSync (fs.js:1409:5)
    at asyncOutputFilteredFile (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/index.js:173:12)
    at tryCatch (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:538:13)
    at /Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:606:14
    at flush (/Users/steve/code/myapp/myapp/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:2415:5)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

The only file that starts with auto-import-fastboot-* is

find . -name 'auto-import-fastboot*'
./dist/assets/auto-import-fastboot.js

which is empty.

I am not sure if this is a fastboot or auto-import related error. And I don’t have a clue why I am starting to see this locally, but not on CI. Any ideas what might be going on?

Maybe this gives a hint: the last ting the build process puts out before displaying that error is:

[Babel: app > applyPatches]
cleaning up...

Finally found something, as CI started to fail with a different error (which luckily contained a useable stacktrace). I am using broccoli-strip-debug and something causes it to fail. If I remove it, my build runs through again.

ember-cli-build.js:

 let tree = app.toTree();

  if (app.env === 'production') {
    console.log('stripping debug statements...');
    let stripDebug = require('broccoli-strip-debug');
    tree = new stripDebug(tree);
    console.log('done stripping debug statements...');
  }

What’s quite strange to me is that the log statements are printed at the beginning of the build, however, the build fails after doing a lot of other stuff.

That’s because broccoli doesn’t work synchronously. new stripDebug only sets up the transform, it doesn’t actually do any work until later when broccoli decides to rebuild.

I would put a debugger statement in broccoli-strip-debug’s processString() method and see what’s going on there. It seems like it’s not returning a string, which breaks broccoli-filter.

But also, I think an easier way to get this feature is via a babel plugin like remove-console, because your code is already going through babel anyway. It would like look this in ember-cli-build.js:

let app = new EmberApp({
  babel: {
    plugins: [
      require.resolve('babel-plugin-transform-remove-console')
    ]
  }
});
1 Like

Ah, thanks so much for the clarification. That makes sense. I just started to replace all console.log references with ember debug statements. It’s not that many statements, so that’s ok and it’s easy to find and replace. Though, I’ll lose the different log levels - but maybe even that will be ok. If not, I am going back to console for warn and error and try to strip them with babel. Thanks again. I just realise I should set some time aside to check out how ember is built somewhen.

Just glad to see broccoli-strip-debug go, as I was also having issues getting it to work with embroider, when I last tried it.

Oh no! Now it complains when running fastboot instead of when building the app:

Jul 21 21:54:24 test-01 fastboot[1029]: SyntaxError: Unexpected token '?'
Jul 21 21:54:24 test-01 fastboot[1029]:     at new Script (vm.js:88:7)
Jul 21 21:54:24 test-01 fastboot[1029]:     at VMSandbox.eval (/srv/fastboot/node_modules/fastboot/src/vm-sandbox.js:13:22)
Jul 21 21:54:24 test-01 fastboot[1029]:     at /srv/fastboot/node_modules/fastboot/src/ember-app.js:190:15
Jul 21 21:54:24 test-01 fastboot[1029]:     at Array.forEach (<anonymous>)
Jul 21 21:54:24 test-01 fastboot[1029]:     at EmberApp.loadAppFiles (/srv/fastboot/node_modules/fastboot/src/ember-app.js:187:21)
Jul 21 21:54:24 test-01 fastboot[1029]:     at EmberApp.retrieveSandboxedApp (/srv/fastboot/node_modules/fastboot/src/ember-app.js:235:10)
Jul 21 21:54:24 test-01 fastboot[1029]:     at new EmberApp (/srv/fastboot/node_modules/fastboot/src/ember-app.js:61:21)
Jul 21 21:54:24 test-01 fastboot[1029]:     at FastBoot._buildEmberApp (/srv/fastboot/node_modules/fastboot/src/index.js:114:17)
Jul 21 21:54:24 test-01 fastboot[1029]:     at new FastBoot (/srv/fastboot/node_modules/fastboot/src/index.js:52:10)
Jul 21 21:54:24 test-01 fastboot[1029]:     at Worker.buildMiddleware (/srv/fastboot/node_modules/fastboot-app-server/src/worker.js:74:21)
Jul 21 21:54:24 test-01 fastboot[1029]: [2020-07-21T19:54:24.766Z][m1029] worker exited with error code: 1
Jul 21 21:54:24 test-01 fastboot[1029]: [2020-07-21T19:54:24.771Z][m1029] forked worker 15572
Jul 21 21:54:24 test-01 fastboot[1029]: [2020-07-21T19:54:24.772Z][m1029] worker online
Jul 21 21:54:24 test-01 fastboot[1029]: [2020-07-21T19:54:24.774Z][m1029] worker exited with error code: 1
Jul 21 21:54:24 test-01 fastboot[1029]: [2020-07-21T19:54:24.779Z][m1029] forked worker 15573
Jul 21 21:54:24 test-01 fastboot[1029]: [2020-07-21T19:54:24.779Z][m1029] worker online
Jul 21 21:54:25 test-01 fastboot[1029]: /srv/fastboot/dist/assets/vendor-95aa7e7683988dcc0eb14315608a1a91.js:7412
Jul 21 21:54:25 test-01 fastboot[1029]: class a{constructor(e,t,r){n(this,"name",void 0),n(this,"element",void 0),n(this,"multiple",void 0),n(this,"onChange",void 0),this.name=e,this.element=t,this.multiple=r.multiple??!1,this.onChange=r.onChange}}var i=new WeakMap,o=new WeakMap

I remember I recently read about a fastboot app which suddenly had the same error. And it turns out it’s the same issue. Modifying targets to use 'Chrome >= 78' solved the fastboot issue.

1 Like

So this issue is that you need to add node: 'current' to your targets file. Its something that I’m working on fixing the default behaviour for ember-cli-fastboot at the moment.

Here is an example targets file:

'use strict';

const browsers = [
  'last 1 Chrome versions',
  'last 1 Firefox versions',
  'last 1 Safari versions'
];

const isCI = !!process.env.CI;
const isProduction = process.env.EMBER_ENV === 'production';

if (isCI || isProduction) {
  browsers.push('ie 11');
}

module.exports = {
  browsers,
  node: 'current'
};
2 Likes

Ah, yes. Thanks so much. That fixes the issue and is so much nicer.

1 Like