redux-flash-notification icon indicating copy to clipboard operation
redux-flash-notification copied to clipboard

Import declarations may only appear at top level of a module

Open kathgironpe opened this issue 7 years ago • 5 comments

I get this error:

import declarations may only appear at top level of a module

I followed suggestions. Not sure what's wrong. I use the latest version of Redux and React.js.

kathgironpe avatar Jul 18 '16 13:07 kathgironpe

can you show me where the error appear?

posabsolute avatar Jul 18 '16 14:07 posabsolute

It only appears when I add the import line on a layout view, which is the only one I have for the app. I'm a few hours away from demo hour but I will get an app example to confirm the problem later.

kathgironpe avatar Jul 18 '16 14:07 kathgironpe

okay, it seems it's just a question of some code being before an import statement, very curious, I use this thing in all my projects and never had this error, I can try to debug it with you if you are interested

posabsolute avatar Jul 18 '16 18:07 posabsolute

I used redux-notifications and it worked. That too, has some problems, which I can live with for now. Still I like to check to create app to confirm the problem with this later.

kathgironpe avatar Jul 18 '16 18:07 kathgironpe

I'm experiencing this error. I haven't actually used the import anywhere; the error is thrown because the module is in es6 and my webpack fails to transpile it, for some reason. Can you share your webpack and babelrc? Here are my files:

//webpack

var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
  template: __dirname + '/app/index.html',
  filename: 'index.html',
  inject: 'body'
});
var path = require('path')
var webpack = require('webpack');

module.exports = {
  devtool: 'source-map',
  entry: [
    'webpack-hot-middleware/client?reload=true',
    path.join(__dirname, './app/index.js')
  ],
  module: {
    loaders: [{
      test: [/\.js$/,/\.jsx$/],
      loader: "babel-loader",
      include: [
         path.resolve(__dirname, "node_modules/flash-notification-react-redux"),
         path.resolve(__dirname, "./app")
      ],
    },{
      test: /\.(css|scss)$/,
      loader: ExtractTextPlugin.extract('css!sass')
    },{
      test: /\.(png|jpg)$/,
      loader: 'url-loader?limit=8192'
    }]
  },
  output: {
    filename: 'index.bundle.js',
    path: __dirname + '/dist',
    publicPath: '/'
  },
  plugins: [
    HTMLWebpackPluginConfig,
    new ExtractTextPlugin('public/style.css', {
      allChunks: true
    }),
    new webpack.HotModuleReplacementPlugin(),
  ]
}
//babelrc
{
  presets: [ 'es2015', 'stage-0', 'react'],
  plugins: ['transform-decorators-legacy']
}

i can open a new issue if you'd like, thanks.

minifigmaster125 avatar Dec 04 '16 01:12 minifigmaster125