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

Error on Webpack 2 #34

Closed
lucasbento opened this issue Feb 9, 2017 · 5 comments · Fixed by #35
Closed

Error on Webpack 2 #34

lucasbento opened this issue Feb 9, 2017 · 5 comments · Fixed by #35

Comments

@lucasbento
Copy link
Contributor

I'm getting this useless error message:

Uncaught SyntaxError: Unexpected token : which comes from bundle.js:6470, the exact line where the environment is defined:

// bundle.js:6470

{"GRAPHQL_URL":"http:https://localhost:5001/graphql","PORT":"7001"}.NODE_ENV !== 'production' ? warning(element, 'ReactComponentTreeHook: Missing React element for debugID %s when ' + 'building stack', id) : void 0;

This is my webpack config:

// webpack.config.js

/* eslint-disable */

const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const dotEnv = require('dotenv-webpack');

const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || '7001';

module.exports = {
  context: path.resolve(__dirname, './'),
	entry: [
		`webpack-dev-server/client?http:https://${HOST}:${PORT}`,
		`webpack/hot/only-dev-server`,
		'./src',
	],
	// devtool: 'source-map',
	output: {
		path: path.join(__dirname, 'admin'),
		filename: 'bundle.js'
	},
	resolve: {
    modules: [
      path.join(__dirname, 'src'),
			'node_modules',
		],
    extensions: ['.js'],
	},
	module: {
    rules: [{
  		test: /\.js?$/,
      exclude: [/node_modules/],
      use: 'babel-loader',
      include: path.join(__dirname, 'src'),
  	}],
	},
	devServer: {
		contentBase: path.resolve(__dirname, 'admin'),
		noInfo: true,
		hot: true,
		inline: true,
		historyApiFallback: true,
		port: PORT,
		host: HOST,
    stats: {
      assets: true,
      colors: true,
      version: false,
      hash: false,
      timings: true,
      chunks: false,
      chunkModules: false
    },
	},
	plugins: [
		new webpack.NoEmitOnErrorsPlugin(),
		new webpack.HotModuleReplacementPlugin(),
		new HtmlWebpackPlugin({
			template: './src/index.html',
		}),
    new dotEnv({
      path: './.env',
    }),
	]
};

And this is my .env:

GRAPHQL_URL=http:https://localhost:5001/graphql
PORT=7001

Can you point me the way to fix it? I can also send a PR if it's a problem on the package itself.

Versions

dotenv-webpack: 1.4.0
webpack: 2.2.1
webpack-dev-server: 2.3.0

@piersroberts
Copy link
Contributor

Yep, same problem here

@mrsteele
Copy link
Owner

mrsteele commented Feb 9, 2017

Thanks for brining this to my attention @lucasbento and @piersroberts and the likers.

I might need some more information because I can get this to work just fine in my simplified example app (just pushed that to https://github.com/mrsteele/dotenv-webpack-example so please check it out to compare with what you are doing).

I can get all my console logs to show just fine, so maybe its a conflict with another package?

piersroberts pushed a commit to piersroberts/dotenv-webpack that referenced this issue Feb 9, 2017
@piersroberts
Copy link
Contributor

I've raised a PR which fixes it for me

@mrsteele
Copy link
Owner

mrsteele commented Feb 9, 2017

Hmmm, yeah it doesn't mess up any of my local tests, can anyone else confirm @piersroberts's approach fixes the problem?

@mrsteele
Copy link
Owner

mrsteele commented Feb 9, 2017

I have accepted @piersroberts pull request and semantic release is pushing v1.4.1. Please check and be sure that this has resolved the problem.

Thank you @piersroberts for the PR and thank you @lucasbento for reporting!

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

Successfully merging a pull request may close this issue.

3 participants