Stencil: rollup-plugin-dotenv throwing error

Created on 30 Jan 2020  路  5Comments  路  Source: ionic-team/stencil

Stencil version:

 @stencil/[email protected]

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
I feel this is a Stencil bug not one of the plugins. On the other hand I'm not a rollup pro. Sorry if it's a plugin issue.

The rollup-plugin-dotenv is giving me headaches with this string from @stencil :

'\nimport { bootstrapLazy, patchEsm, globals } from \'@stencil/core\';\n\nexport const defineCustomElements = (win, options) => {\n  return patchEsm().then(() => {\n    globals();\n    bootstrapLazy([/*!__STENCIL_LAZY_DATA__*/], options);\n  });\n};\n',

I think it might be related to this line of code:
https://github.com/ionic-team/stencil/blob/b3b69933528b7106ff69720797ecaabec74e4546/src/compiler/component-lazy/generate-lazy-app.ts#L93

That鈥檚 the rollup error 1.8.6:

[ ERROR ]  Rollup: Plugin Error
           replacement content must be a string (plugin: dotenv, transform)

In 1.8.4 it threw a different error:

[ ERROR ]  Rollup: Plugin Error
           functionValues[match[1]] is not a function (plugin: dotenv, transform)

Expected behavior:
Compiles without errors

Steps to reproduce:
https://github.com/bitflower/stencil-rollup-dotenv-issue

triage

Most helpful comment

For others that hit this: this happens with rollup-plugin-dotenv when you don't have a .env with at least one variable set. If you're deploying to a host that lets you set env variables externally, you'll still want to create a dummy .env and give it a value first

All 5 comments

I debugged the plug like this:

Bildschirmfoto 2020-01-30 um 16 08 27

Result of plug debugging:

[01:23.5]  bundling components started ...
BF ROLL-REPLACE 3 { magicString: MagicString {},
  code:
   '\nimport { bootstrapLazy, patchBrowser, globals } from \'@stencil/core\';\npatchBrowser().then(options => {\n  globals();\n  return bootstrapLazy([/*!__STENCIL_LAZY_DATA__*/], options);\n});\n',
  pattern: /\b()\b/g }
BF ROLL-REPLACE 4 [ '',
  '',
  index: 1,
  input: '\nimport { bootstrapLazy, patchBrowser, globals } from \'@stencil/core\';\npatchBrowser().then(options => {\n  globals();\n  return bootstrapLazy([/*!__STENCIL_LAZY_DATA__*/], options);\n});\n',
  groups: undefined ]
BF ROLL-REPLACE 5 TypeError: functionValues[match[1]] is not a function
    at Object.transform (/Users/matthias/Documents/Projekte/Temp/dotenv-test/node_modules/rollup-plugin-replace/dist/rollup-plugin-replace.cjs.js:86:51)
    at Promise.resolve.then (/Users/matthias/Documents/Projekte/Temp/dotenv-test/node_modules/@stencil/core/dist/sys/node/index.js:23077:25)
BF ROLL-REPLACE 3 { magicString: MagicString {},
  code:
   '\nimport { bootstrapLazy, patchEsm, globals } from \'@stencil/core\';\n\nexport const defineCustomElements = (win, options) => {\n  return patchEsm().then(() => {\n    globals();\n    bootstrapLazy([/*!__STENCIL_LAZY_DATA__*/], options);\n  });\n};\n',
  pattern: /\b()\b/g }
BF ROLL-REPLACE 4 [ '',
  '',
  index: 1,
  input: '\nimport { bootstrapLazy, patchEsm, globals } from \'@stencil/core\';\n\nexport const defineCustomElements = (win, options) => {\n  return patchEsm().then(() => {\n    globals();\n    bootstrapLazy([/*!__STENCIL_LAZY_DATA__*/], options);\n  });\n};\n',
  groups: undefined ]
BF ROLL-REPLACE 5 TypeError: functionValues[match[1]] is not a function
    at Object.transform (/Users/matthias/Documents/Projekte/Temp/dotenv-test/node_modules/rollup-plugin-replace/dist/rollup-plugin-replace.cjs.js:86:51)
    at Promise.resolve.then (/Users/matthias/Documents/Projekte/Temp/dotenv-test/node_modules/@stencil/core/dist/sys/node/index.js:23077:25)
[01:23.8]  copy finished (3 files) in 274 ms
BF ROLL-REPLACE 3 { magicString: MagicString {}, code: '', pattern: /\b()\b/g }
[01:24.0]  generate styles finished in 496 ms

Closed as not Stencil related....

For others that hit this: this happens with rollup-plugin-dotenv when you don't have a .env with at least one variable set. If you're deploying to a host that lets you set env variables externally, you'll still want to create a dummy .env and give it a value first

fixed with this dirty trick on stencil.config.ts

import dotenvPlugin from 'rollup-plugin-dotenv';
import fs from 'fs';
let dotenv = () => '';
try {
  if (fs.existsSync('./.env')) {
    dotenv = dotenvPlugin;
  }
} catch (err) {
}
Was this page helpful?
0 / 5 - 0 ratings