[BUG] 1.6 - 1.7 beta 8 and RC2 - Error loading node_modules

Im having this message in a test project with node_modules:

It works fine with 1.5.3.

I also tested it with other modules. All have the same issue.
My computer is OSX with High Sierra (but I dont think this is relevant).
Anybody else had issues with node modules?

Edit 1: the issues is with TypeScript files only (works fine with JS) and with 1.6-1.7. I guess Im the only here working with node modules and TS?? I just opened and issue in github: [1.6-1.7beta] npm modules error - Only TS · Issue #2130 · cocos/cocos-engine · GitHub

You are probably using any third party library which already has a folder named node_modules locate that and rename it to something different that should resolve it.

I dont understand what you mean… There are no issues with version 1.5.2 and fails with 1.6+. How is that possible?
And this is a fresh OSX setup in a new computer. I installed Creator today for the fist time.

is this a new project? If yes then i can’t help you much in this regard. If this is a old project in that case try searching a folder node_modules in you project root directory, your project probably contains something named node_modules which is in conflict with cocos creator project itself.

Yes, its a project made from scratch. Its actually a hello world TS project with 1 module. I made it as a test case. So I guess its actually a bug.

Updated first post with the issue I posted on github.

No problems on 1.7 b7.

I installed tweenmax with npm and import it from a .ts file with
import { TweenMax, Power2, TimelineLite } from 'gsap';

Yeah, confirmed it works with gsap. But it doesnt work with ‘moment’. Try import moment and the following syntax:
import * as moment from “…/…/node_modules/moment”;

And you will see the error (this works just fine in 1.5.2). Not sure if the issue its the modules (tried with moment and eventManager) or the syntax.

try import * as moment from "moment";

2 Likes

So, I found out the issue…thanks to you!!! In 1.5.2 I had to import using this syntax:
import * as moment from “…/…/node_modules/moment”; <— includes path to node_modules folder

But starting on version 1.6 I have to do it without path:

import * as moment from “moment”;

Now it works. So I had the warning because I moved from a previous version. I will update the issue on github. thanks @phero_constructs!!! :smiley:

3 Likes

I’ve got a response from the dev team in Github:

“You should not use npm modules, its deprecated since 1.3. Use plugin scripts instead.”

@phero_constructs are you aware they deprecated support to npm modules? I dont understand what they mean for “plugin scripts”…

Edit1: it seems there is a new documentation and a new section about it: http://www.cocos2d-x.org/docs/creator/en/scripting/plugin-scripts.html

Can we get a little clarification on this?

We’re using npm modules extensively, and without issue. We are specifically targeting mobile, however we do extensive testing and debugging using both the web browser and the Cocos simulator. We’re currently using v1.6.2 stable, the project is written in TypeScript.

Quickly looking through that plugin script documentation, it looks quite frankly extremely difficult to use. We’re using several libraries that rely on other libraries etc, trying to merge them down into on file may even be impossible.

So, if “node_modules” have been deprecated since 1.3, why is this the first mention of it? I’ve searched through the blog and forum posts and could not find anything. Why are they being deprecated, I can appreciate the engine team not wanting to work on issues that stem from people using an module that isn’t compatible with the creator ecosystem. But that shouldn’t prevent other people from using pure JS modules that don’t rely on the DOM or node APIs in our projects.

I would appreciate any insight the team could provide on this issue.

Thank you.

1 Like

Pingning @slackmoehrle so he can read the thread and get a clarification for us.

@jrosich Yes, I saw the deprecation mentioned butI continued using it since it is still working. I would be sad to see node modes go. There are a lot of good libraries there and converting them to plugins would be extra work I’d rather avoid.

I’m still using modules with CC 1.7b8 and I hope to upgrade to 1.7 final without losing this functionality.

Let us ask @jare to take a look at this.

1 Like