apm-agent-rum-js icon indicating copy to clipboard operation
apm-agent-rum-js copied to clipboard

Vite build: Unexpected keyword 'false' in service-factory.js

Open phlegx opened this issue 1 year ago • 5 comments

Hi!

I use Vite 4.x, Vue 3.x and @elastic/apm-rum-vue 2.1.2. Building the app I get this error:

[vite-plugin-pwa:build] Unexpected keyword 'false' (7:9) in /.../vue3/node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js
file: /.../vue3/node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js:7:9
5: import LoggingService from './logging-service';
6: import { CONFIG_CHANGE, CONFIG_SERVICE, LOGGING_SERVICE, APM_SERVER } from './constants';
7: import { __DEV__ } from '../state';
            ^
8: var serviceCreators = (_serviceCreators = {}, _serviceCreators[CONFIG_SERVICE] = function () {
9:   return new ConfigService();
file:///.../vue3/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:21186
  var err = new SyntaxError(message);
            ^

SyntaxError: Unexpected keyword 'false' (7:9) in /.../vue3/node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js

Is it a bug or a misconfiguration?

phlegx avatar May 26 '23 10:05 phlegx

Having the same issue

luc-anise avatar Sep 12 '23 14:09 luc-anise

Problem still exists. @luc-anise have you found a solution in the meantime?

phlegx avatar May 02 '24 10:05 phlegx

I was using vite and had a custom env variable for dev so I removed that and it worked

luc-anise avatar May 02 '24 12:05 luc-anise

I use rollup plugin replace like described in the documentation https://www.elastic.co/guide/en/apm/agent/rum-js/current/install-the-agent.html#_rollup but it does not work. On build __DEV__ is always true.

plugins: [
  replace({
    'process.env.NODE_ENV': JSON.stringify('production')
  })
]
[commonjs--resolver] Unexpected keyword 'true' (9:9) in node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js
file: node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js:9:9
 7: import LoggingService from './logging-service';
 8: import { CONFIG_CHANGE, CONFIG_SERVICE, LOGGING_SERVICE, APM_SERVER } from './constants';
 9: import { true } from '../state';

If I build in production mode, then I get the same error but Unexpected keyword 'false'.

[commonjs--resolver] Unexpected keyword 'false' (9:9) in node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js
file: node_modules/@elastic/apm-rum-core/dist/es/common/service-factory.js:9:9
 7: import LoggingService from './logging-service';
 8: import { CONFIG_CHANGE, CONFIG_SERVICE, LOGGING_SERVICE, APM_SERVER } from './constants';
 9: import { false } from '../state';

phlegx avatar May 02 '24 13:05 phlegx

How can I exclude apm-agent-rum-js from __DEV__ replacement, caused by vite-ssr module? vite-ssr uses the same naming __DEV__ and uses define: in Vite config. Maybe a more package specific naming like __ELASTIC_APM_RUM_DEV__ could be very useful.

phlegx avatar May 02 '24 15:05 phlegx