Unexpected token: punc (.)

See original GitHub issue

Version: 5.1.0 Node: 15.0.1 Webpack: 5.4.0

In webpack:

  new Dotenv({
      path: path.resolve(__dirname, '../../config', '.env.production'),
    }),

This causes error somehow. Error:

ERROR in server.bundle.js from Terser
Unexpected token: punc (.) [server.bundle.js:3367,6]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:51 (19 by maintainers)

github_iconTop GitHub Comments

5reactions
moroinecommented, Apr 26, 2021

I’m using a library which is relying on process.env[name] dynamically. So replacing with MISSING_ENV_VAR is not working.

I had to remove dotenv-plugin for @lid3rs solution adapted to bypass the syntax error:

const { config: configDotEnv } = require('dotenv');
const { DefinePlugin, ProvidePlugin } = require('webpack');
const dotenv = configDotEnv();
new ProvidePlugin({ process: 'process' }),
new DefinePlugin({
  'process.env': `(${JSON.stringify(dotenv.parsed)})`,
}),

@mrsteele do you think we could do this in dotenv-plugin instead?

2reactions
mrsteelecommented, May 4, 2021

@moroine a few things:

  1. This is not on topic with the issue, and this issue has closed. Please open a new ticket if you would like to discuss.
  2. If we kept all the envs, we are not really bundling envs anymore but stashing all of them which does not meet one of the plugin goals (Only bundle what you use for security purposes and bundle sizes like @sapkra mentions)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uglify SyntaxError: Unexpected token: punc ()) - Stack Overflow
I am trying to use gulp in order to minify a folder containing JS files. However, one of the files has the above...
Read more >
Unexpected token: punc (() - ES6 parsing errors using @babel ...
The error only occurs when running my project in a production environment with UglifyJS enabled. In development, the project run fine.
Read more >
terser minification error (SyntaxError:Unexpected token: punc ...
I am attempting to upgrade to meteor@2.4-rc.0 from meteor@2.2.3. Development with meteor run works fine. I am getting the following stack ...
Read more >
Unexpected token: punc(;) - Medium
Unexpected token : punc(;). Recently in my angular application there was a page (component) that was really starting to get quite ...
Read more >
ERR_UNHANDLED_REJECTION Unexpected token: punc ...
ERR_UNHANDLED_REJECTION Unexpected token: punc (.) terser ... I'm getting a prod only build error that wasn't very helpful with no line numbers ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found