ardatan / meteor-webpack

https://medium.com/@ardatan/meteor-with-webpack-in-2018-faster-compilation-better-source-handling-benefit-from-bc5ccc5735ef
MIT License
123 stars 29 forks source link

Error resolving module imports #4

Closed aogaili closed 6 years ago

aogaili commented 6 years ago

Thanks for the interesting package!

I'm running into the following error:


ERROR in ./server/main.js
Module not found: Error: Can't resolve '/imports/startup/server' in '/Users/ali/Development/Meronex/Applications/Products/Meronex Communities/meronex-communities/server'
 @ ./server/main.js 1:0-33
 @ multi ./server/main.js

The ./server/main.js has the following line:

import '/imports/startup/server';

Any idea what might be causing this? I think it might be due to the absolute paths since in the examples we've relative paths.

filipenevola commented 6 years ago

I'm with the same problem, I'm migrating to relative imports just to check it everything else is working.

I'm also using only .js extension, migrating the React files to .jsx to see if I can run with webpack setup.

aogaili commented 6 years ago

Ah I've the same setup and I'm also using .js extensions instead of .jsx.

However we're using absolute imports everywhere so it'll be major refactoring, perhaps I can test it on a smaller project until you do your refactoring.

filipenevola commented 6 years ago

I'm doing the same, starting on a smaller project, but if we can make it work, it'll be a major win for Meteor community :wink:

ardatan commented 6 years ago

Thank you for all your support :) I think same with you. Meteor community needs this kind of packages to keep Meteor alive and growing. After that, I will try to reproduce your problem. Also I am now working on creating test environment with Webpack and make this package support test tools like Karma etc.

aogaili commented 6 years ago

Thanks @ardatan!

I'm curious though, how is this package different from the existing older one on atmosphere?

ardatan commented 6 years ago

I created this package from scratch without using this old one. New package uses the regular configuration structure and using the dependencies in your project’s node_modules instead of using the ones installed with ‘Npm.depends’. So the package doesn’t include ‘webpack’ and other dependencies . You can also add any webpack plugins by installing them via npm and add them to your ‘webpack.config’ llike the same way with ‘Webpack CLI’. In the old package, you have to install ‘webpack:typescript’ for TS support etc. You don’t need this in new package, just install your favorite ts plugin and add it to config file.

ardatan commented 6 years ago

You can use webpack.config.js resolve configuration settings to use similar path in your imports.

ardatan commented 6 years ago

I am closing this issue. If you experience any problems, please open a new issue.

Thanks!

jlmbaka commented 6 years ago

Hi @ardatan, I am experiencing the same problème and I cannot seem to find the accepted solution to this problem. Can You tell me how to fix this problem ?

filipenevola commented 6 years ago

Hello @aliogaili and @jlmbaka, I'm able to use like this:

import AdminPage from 'imports/ui/containers/shared/admin-page';

with this setup on webpack


  resolve: {
    extensions: ['*', '.js', '.jsx'],
    alias: {
      imports: path.resolve(__dirname, 'imports/'),
    },
  },

I believe in your case you just need to find/replace all imports in your source code from /imports/ to imports/ (removing the first slash)